Search code examples
asp.net-corerazor

How to redirect to a customized access denied page if authorization is not met?


I’m using Authorize(Roles = "HRManager,Finance")] on top of each razor pages to restrict user access. ( it works fine). How to redirect the faild access attempt to a customized access denied page?

I developed the access denied page. But,how to call it when a user is not authianticated?


Solution

  • If you use startup ,try :

    services.ConfigureApplicationCookie(opts =>
                {                   
                    opts.AccessDeniedPath = "/xxx/xxx";
                });