How to create custom 401 error page in mvc using windows authentication

I'm trying to make a custom 401 (unauthorized) page

using mvc 5

with Windows Authentication I inherited mine AuthorizeEnumAttribute

from AuthorizeAttribute

and marked its actions. nothing special.

By default, if the user has access (isinrole), the page is displayed, and if not, the standard browser login / password dialog is displayed. if the user has entered credentials that do not have a special role, they are prompted for credentials again. After canceling the user click, I see the standard IIS error page"HTTP Error 401.0 - Unauthorized"

Can I replace this page in some way with my own when the user cancels the cancellation?

I tried override HandleUnauthorizedRequest

and added httpError

in web.config

, but both are redirected to a custom page in the case of an unauthorized user, but not prompting for credentials, which doesn't suit my needs.

I see in the fiddler that after canceling there are no requests to the server, and after canceling it shows the previously loaded iis 401 page

Is there a way to show my html after canceling?

early.

+3


source to share





All Articles