当前位置: 首页>>代码示例>>C#>>正文


C# IApplicationBuilder.UseWebSockets方法代码示例

本文整理汇总了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?}");
            });
        }
开发者ID:iKadmium,项目名称:kadmium-osc-dmx-dotnet,代码行数:32,代码来源:Startup.cs

示例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);
        });
    }
开发者ID:jbuiss0n,项目名称:HelloWorldVNext,代码行数:26,代码来源:Startup.cs

示例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);
            });
        }
开发者ID:tuespetre,项目名称:Sleeper,代码行数:26,代码来源:Startup.cs

示例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();
        }
开发者ID:Mmmattias,项目名称:SignalR-AspNet5,代码行数:29,代码来源:Startup.cs

示例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();
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:34,代码来源:Startup.cs

示例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>();
        }
开发者ID:XuPeiYao,项目名称:AspNetCoreTemplate,代码行数:41,代码来源:Startup.cs

示例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");
 }
开发者ID:tmds,项目名称:Tmds.SockJS,代码行数:11,代码来源:Startup.cs

示例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();
        }
开发者ID:aluitink,项目名称:Ojibwe,代码行数:13,代码来源:Startup.cs

示例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();
            });
        }
开发者ID:DovydasNavickas,项目名称:AspNet.Security.OpenIdConnect.Samples,代码行数:52,代码来源:Startup.cs

示例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");
        }
开发者ID:nimesh89,项目名称:wizchat,代码行数:14,代码来源:Startup.cs

示例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();
 }
开发者ID:haydenmc,项目名称:BoinkChat,代码行数:13,代码来源:Startup.cs

示例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();
            });
        }
开发者ID:streamcode9,项目名称:chat,代码行数:13,代码来源:WebSocketsHelper.cs

示例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();
        }
开发者ID:RoviSys,项目名称:SignalR-Server,代码行数:15,代码来源:Startup.cs

示例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();
        }
开发者ID:FabianGosebrink,项目名称:ASPNET-Core-Angular2-SignalR-Typescript,代码行数:17,代码来源:Startup.cs

示例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);
                }
            });
        }
开发者ID:McBits,项目名称:DungeonR,代码行数:20,代码来源:Startup.cs


注:本文中的IApplicationBuilder.UseWebSockets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。