AspNetCore.SignalR 2.1 and CORS

前端 未结 6 1418
梦谈多话
梦谈多话 2020-12-29 06:49

I\'m migrating our SignalR-Service to the new AspNetCore.SignalR (2.1 preview) and now I get problems with CORS. I will never access the service from the same origin, so I n

6条回答
  •  梦谈多话
    2020-12-29 07:07

    If you're migrating your project to asp.net core version 3.x, you can upgrade routing from the Configure method like this:

    app.UseCors("AllowCors");
    
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
    
        endpoints.MapHub("/test");
    });
    

    app.UseMvc and app.UseSignalR will be replaced with app.UseEndpoints. app.UseSignalR also cannot be used anymore because:

    This method is obsolete and will be removed in a future version.

提交回复
热议问题