How do I serve up an Unauthorized page when a user is not in the Authorized Roles?

前端 未结 5 767
眼角桃花
眼角桃花 2020-12-04 15:54

I am using the Authorize attribute like this:

[Authorize (Roles=\"Admin, User\")]
Public ActionResult Index(int id)
{
    // blah
}
5条回答
  •  长情又很酷
    2020-12-04 16:22

    And HttpUnauthorizedResult (this comes as reuslt of the AuthorizeAtrribute) just sets StatusCode to 401. So probably you can setup 401 page in IIS or custom error pages in web.config. Of course, you also have to ensure that access to your custom error page is not requires authorization.

提交回复
热议问题