简体   繁体   English

WebSocket 与 asp.net 样板框架

[英]WebSocket with asp.net boilerplate framework

I'm trying to use a native WebSocket with asp.net boilerplate (.NET Core 5) but the problem is the WebSocket always returns 0 status for the WebSocket client, and on PostMan the status keeps CONNECTING I'm trying to use a native WebSocket with asp.net boilerplate (.NET Core 5) but the problem is the WebSocket always returns 0 status for the WebSocket client, and on PostMan the status keeps CONNECTING

在此处输入图像描述

I don't have any errors and I added the configuration properly as below:我没有任何错误,我正确添加了配置,如下所示:

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {

            app.UseWebSockets();
            app.Use(async (context, next) => {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();

                }
                else
                {
                    await next();
                }
            });

            app.UseAbp(options => { options.UseAbpRequestLocalization = false; }); // Initializes ABP framework.

            app.UseCors(_defaultCorsPolicyName); // Enable CORS!

            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAbpRequestLocalization();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<AbpCommonHub>("/signalr");
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
            });

            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/swagger.json"; });

            // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
            app.UseSwaggerUI(options =>
            {
                // specifying the Swagger JSON endpoint.
                options.SwaggerEndpoint($"/swagger/{_apiVersion}/swagger.json", $"LocateCRM API {_apiVersion}");
                options.IndexStream = () => Assembly.GetExecutingAssembly()
                    .GetManifestResourceStream("LocateCRM.Web.Host.wwwroot.swagger.ui.index.html");
                options.DisplayRequestDuration(); // Controls the display of the request duration (in milliseconds) for "Try it out" requests.  
            }); // URL: /swagger


           
        }

Is there any issue with my configuration:我的配置有问题吗:

 app.UseWebSockets();
            app.Use(async (context, next) => {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();

                }
                else
                {
                    await next();
                }
            });

The issue was in the path that I'm using in the client side:问题出在我在客户端使用的路径中:

it was它是

ws://localhost:4200

and it has to be它必须是

ws://localhost:4200/ws

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET样板+ SignalR - ASP.NET Boilerplate + SignalR ASP.NET Boilerplate .NET Core 2 - ASP.NET Boilerplate .NET Core 2 将 .Net Core 2.2 和 ASP.NET 样板 4.5 升级到 .Net Core 3.1 和 ASP.NET 样板 5.13 时出现 ObjectMapper 错误 - ObjectMapper Error when Upgrade .Net Core 2.2 & ASP.NET Boilerplate 4.5 to .Net Core 3.1 & ASP.NET Boilerplate 5.13 如何在 ASP.NET 样板中获取当前事务? - How to get current transaction in ASP.NET Boilerplate? ASP.NET Core(.NET Core)和ASP.NET Core(.NET Framework)之间的区别 - Difference between ASP.NET Core (.NET Core) and ASP.NET Core (.NET Framework) Asp.Net核心(Full .Net框架)与Asp.Net核心(.Net Core)性能 - Asp.Net core (Full .Net framework) vs Asp.Net core (.Net Core) Performance 缺少“ASP.NET核心Web应用程序(.NET Framework)”模板 - missing “ASP.NET Core Web Application (.NET Framework)” template 将Asp.net Core中的ConfigurationManager与.NET Framework网站一起使用 - Using ConfigurationManager in Asp.net Core with .NET Framework website ASP.NET Core引用的.NET Framework中的程序集FileNotFound - Assembly FileNotFound in .NET Framework referenced by ASP.NET Core 如何使用 dotnet 构建 .NET Framework ASP.NET 应用程序 - How to build .NET Framework ASP.NET app using dotnet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM