[英]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.