I am implementing custom Authentication in an ASP.Net Core project without identity.
I have include CookieAuthentication
just before UseMvc
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "Cookie",
LoginPath = new PathString("/Account/Login/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
Add Authorization for custom policy
services.AddAuthorization(options =>
{
options.AddPolicy("CustomPolicy",
policy => policy.RequireClaim("CustomClaim"));
});
And at home controller I used the appropriate auth attribute
[Authorize(Policy = "CustomPolicy")]
public class HomeController : Controller { }
I would expect to be redirected to /Account/Login/
every time I try to access /Home/Index
but I only get 401
.
I followed these two tutorials:
What I am missing?
Update: This problem exists only when I am using IIS to run the app, from the exe the redirection is working properly.
我更新了所有nuget软件包,并解决了所有问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.