本文整理汇总了C#中IApplicationBuilder.UseWebSockets方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseWebSockets方法的具体用法?C# IApplicationBuilder.UseWebSockets怎么用?C# IApplicationBuilder.UseWebSockets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseWebSockets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseWebSockets();
app.UseDefaultFiles();
app.UseStaticFiles();
app.Map("/Preview/Socket", PreviewSocketHandler.Map);
app.Map("/Index/Socket", DashboardSocketHandler.Map);
app.Map("/SACNTransmitters/Socket", SACNTransmitterLive.Map);
app.Map("/OSCListeners/Socket", OSCListenerLive.Map);
app.Map("/RawDMX/Socket", RawDMXSocketHandler.Map);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例2: Configure
public void Configure(IApplicationBuilder app)
{
// Add managed websocket middleware for servers
// that support opaque upgrade (like kestrel)
app.UseWebSockets();
app.Use(async (context, next) =>
{
if (context.IsWebSocketRequest)
{
WebSocket webSocket = await context.AcceptWebSocketAsync();
await EchoWebSocket(webSocket);
}
else
{
await next();
}
});
app.Run(async context =>
{
var payload = "Hello World";
context.Response.ContentLength = payload.Length;
await context.Response.WriteAsync(payload);
});
}
示例3: Configure
public void Configure(IApplicationBuilder app)
{
// Request pipeline
app.UseWebSockets();
app.Use(HandleWebSocketsAsync);
app.UseMvc();
// Initialization
Task.Run(async () =>
{
await InitializeDatabaseAsync();
await InitializeServiceBrokerAsync(app.ApplicationServices);
})
.Wait();
// Background tasks
Task.Run(async () =>
{
await ProcessMessagesAsync(app.ApplicationServices);
});
}
示例4: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseWebSockets();
app.UseSignalR();
}
示例5: Configure
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
LifetimeManager lifetimeManager,
InterpreterManager interpreterManager,
SecurityManager securityManager
) {
lifetimeManager.Initialize();
interpreterManager.Initialize();
app.UseWebSockets(new WebSocketOptions {
ReplaceFeature = true,
KeepAliveInterval = TimeSpan.FromMilliseconds(1000000000),
ReceiveBufferSize = 0x10000
});
var routeBuilder = new RouteBuilder(app, new RouteHandler(RemoteUriHelper.HandlerAsync));
routeBuilder.MapRoute("help_and_shiny", "remoteuri");
app.UseRouter(routeBuilder.Build());
app.UseBasicAuthentication(options => {
options.Events = new BasicEvents { OnSignIn = securityManager.SignInAsync };
});
app.Use((context, next) => {
if (!context.User.Identity.IsAuthenticated) {
return context.Authentication.ChallengeAsync();
} else {
return next();
}
});
app.UseMvc();
}
示例6: Configure
/// <summary>
/// 設定AspNetCore
/// </summary>
/// <param name="app">應用程式建構器</param>
/// <param name="env">環境變數</param>
/// <param name="loggerFactory">記錄檔處理類別</param>
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
#region Development Configure
//加入記錄主控台設定
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
//除錯模式
loggerFactory.AddDebug();
#endregion
#region StaticFiles Configure
//設定預設檔案
ConfigureDefaultFiles(app);
if (!env.IsDevelopment()) {//是否為開發模式
app.UseDeveloperExceptionPage();//使用開發模式錯誤頁面
app.UseDatabaseErrorPage();//使用資料庫錯誤頁面
app.UseBrowserLink();//使用瀏覽器連結
} else {
ConfigureErrorPages(app, env);//設定錯誤頁面對應
}
//使用靜態檔案
app.UseStaticFiles();
#endregion
//使用Session
app.UseSession();
//使用MVC服務,並且載入預設路由設定
app.UseMvc(ConfigureMvcRoute);
//WebSocket設定
app.UseWebSockets<TestChatHanlder>();
}
示例7: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseWebSockets();
app.UseBroadcast("/broadcast");
app.UseEcho("/echo", new SockJSOptions() { MaxResponseLength = 4096 });
app.UseEcho("/disabled_websocket_echo", new SockJSOptions() { UseWebSocket = false });
app.UseEcho("/cookie_needed_echo", new SockJSOptions() { SetJSessionIDCookie = true });
app.UseClose("/close", new SockJSOptions() { HeartbeatInterval = TimeSpan.FromSeconds(10), DisconnectTimeout = CloseDisconnectTimeout });
app.UseTicker("/ticker");
app.UseAmplify("/amplify");
}
示例8: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
Config.ApplicationBase = env.WebRootPath;
var webConfigPath = Path.Combine(Config.ApplicationBase, "web.config");
var logRootDirPath = Config.LoggingDirectory ?? Path.Combine(Config.ApplicationBase, "logs");
loggerFactory.MinimumLevel = LogLevel.Debug;
loggerFactory.AddProvider(new Log4NetLoggerProvider(new FileInfo(webConfigPath), new DirectoryInfo(logRootDirPath)));
app.UseWebSockets();
app.UseMvc();
}
示例9: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment environment, ILoggerFactory factory) {
factory.AddConsole();
factory.AddDebug();
app.UseIISPlatformHandler();
if (environment.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
// Add a new middleware validating access tokens.
app.UseJwtBearerAuthentication(options => {
// Automatic authentication must be enabled
// for SignalR to receive the access token.
options.AutomaticAuthenticate = true;
// Automatically disable the HTTPS requirement for development scenarios.
options.RequireHttpsMetadata = !environment.IsDevelopment();
// Note: the audience must correspond to the address of the SignalR server.
options.Audience = "http://localhost:5000/";
// Note: the authority must match the address of the identity server.
options.Authority = "http://localhost:5000/";
options.Events = new JwtBearerEvents {
// Note: for SignalR connections, the default Authorization header does not work,
// because the WebSockets JS API doesn't allow setting custom parameters.
// To work around this limitation, the access token is retrieved from the query string.
OnReceivingToken = context => {
// Note: when the token is missing from the query string,
// context.Token is null and the JWT bearer middleware will
// automatically try to retrieve it from the Authorization header.
context.Token = context.Request.Query["access_token"];
return Task.FromResult(0);
}
};
});
app.UseWebSockets();
app.UseSignalR<SimpleConnection>("/signalr");
// Add a new middleware issuing access tokens.
app.UseOpenIdConnectServer(options => {
options.Provider = new AuthenticationProvider();
});
}
示例10: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.UseWebSockets();
app.UseSignalR();
app.UseDeveloperExceptionPage();
app.UseExceptionHandler("/Home/Error");
}
示例11: Configure
public void Configure(IApplicationBuilder app)
{
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseWebSockets();
app.UseSignalR();
}
示例12: Configure
public static void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
logger = loggerFactory.CreateLogger("main");
logger.LogVerbose("Configure");
app.UseWebSockets(new WebSocketOptions() { ReplaceFeature = true });
app.Use(async (context, next) =>
{
if (context.WebSockets.IsWebSocketRequest) await InitConnection(context);
else await next();
});
}
示例13: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseWebSockets();
app.Use((context, next) =>
{
context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "*" });
context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "*" });
return next();
});
app.UseFileServer();
app.UseSignalR<RawConnection>("/raw-connection");
app.UseSignalR();
}
示例14: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseCors(config =>
config.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseWebSockets();
app.UseSignalR("/signalr");
app.UseMvc();
}
示例15: Configure
/// <summary>
/// Called by the runtime; configures the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
public void Configure(IApplicationBuilder app)
{
app.UseWebSockets(new WebSocketOptions
{
KeepAliveInterval = TimeSpan.FromSeconds(5)
});
app.Run(async (HttpContext context) =>
{
if (context.WebSockets.IsWebSocketRequest)
{
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
await _server.ProcessWebSocket(context, webSocket);
}
});
}