enb081
enb081

Reputation: 4051

Catch HTTP Error 403.7 - Forbidden in ASP.NET

Is there any way I can redirect the user to a custom page whenever HTTP Error 403.7 - Forbidden occurs in my ASP.NET website?

Upvotes: 0

Views: 963

Answers (1)

Jon P
Jon P

Reputation: 19772

Yes, use your web.config file to set a custom error page:

<customErrors mode="RemoteOnly">
    <error statusCode="403.7" redirect="~/ErrorPages/4037.aspx" />
</customErrors>

Please see the following article

http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/displaying-a-custom-error-page-cs

This article is also worth a look.

Edit

From your comment I'd say that the status code need to be an integer so change it to:

<customErrors mode="RemoteOnly">
    <error statusCode="403" redirect="~/ErrorPages/403.aspx" />
</customErrors>

Edit 2

You can also set CustomError pages in IIS. I'm not sure if it works with sub status though but it is worth a shot.

Upvotes: 2

Related Questions