Friday, July 8, 2011

Custom Error Pages in ASP.NET

First of all, thanks Ted for putting out useful article about this issue.

1. Make sure HTTP errors is enabled/installed in IIS (see picture)



2. Add some code in top-level web.config file. (For example, this displays an ASP.NET page when a 404 error occurs, without rewriting the URL (the visitor will still see the requested URL in the address bar))
- inside <system.webServer>-tag add:

<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/errors/pagenotfound.aspx" responseMode="ExecuteURL" />
</httpErrors>

- inside <system.web>-tag add:

<customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx">
<error statusCode="404" redirect="~/errors/PageNotFound.aspx" />
</customErrors>

3. Create 2 error-pages GeneralError.aspx and PageNotFound.aspx-page in errors-folder.
4. For example, go to SRTR and try to type in URL box something like https://securesrtr.transplant.hrsa.gov/you and hit Enter. PageNotFound must show up.

No comments:

Post a Comment