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

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

I am using the Authorize attribute like this:

[Authorize (Roles=\"Admin, User\")]
Public ActionResult Index(int id)
{
    // blah
}
5条回答
  •  旧时难觅i
    2020-12-04 16:06

    Perhaps a 403 status code is more appropriate based on your question (the user is identified, but their account is not privileged enough). 401 is for the case where you do not know what priveleges the user has.

提交回复
热议问题