ASP.NET 5: Access-Control-Allow-Origin in response

后端 未结 1 1375
别跟我提以往
别跟我提以往 2020-12-20 12:33

From what I understand, when enabled CORS accordingly, the response model should include the following header information (provided that I want to allow everything):

相关标签:
1条回答
  • 2020-12-20 13:16

    Make sure you add app.UseCors before app.UseMvc in your Startup.Configure method, because you need the CORS middleware to be applied before the MVC middleware.

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        ...
    
        //Add CORS middleware before MVC
        app.UseCors("AllowAll");
    
        app.UseMvc(...);
    }
    

    Otherwise the request will be finished before the CORS middleware is applied. This is because UseMvc calls UseRouter which ends up adding the RouterMiddleware, and this middleware only executes the next configured middleware when a route handler wasn't found for the request.

    0 讨论(0)
提交回复
热议问题