Disable Not Authorized Redirect to Account/Login in ASP.NET Core

后端 未结 1 2352
慢半拍i
慢半拍i 2020-12-20 19:49

I have a set of WebAPI services in a shared library. These are used in an ASP.NET Core MVC Web Site and dedicated server only hosting the WebAPI Services without the MVC co

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

    I suspect you have registered ASP.NET Core Identity with both your MVC (Views) Part as well as with your WebApi part.

    You must separate it and the CookieMiddleware (one registered inside .UseIdentity() call) must only be registered for request to your MVC pages, but not for your WebAPI calls.

    You can use the .Map or MapWhen methods (see docs).

    // For requests not going to WebAPI controllers
    app.MapWhen(context => !context.Request.Path.StartsWithSegments("/api"), branch =>
    {
        branch.UseIdentity();
    });
    
    0 讨论(0)
提交回复
热议问题