Pages

Tuesday, August 16, 2011

ASP.NET Custom Errors(customErrors) and URL Mappings (urlMappings)

URL Mappings
  1. Open web.config file. (see MSDN)
  2. Create new urlMappings section within the system.web section.
  3. <urlMappings enabled="true">
    <add url="~/contactus.aspx" mappedUrl="~/index.aspx" />
    </urlMappings>
  4. If user types contactus.aspx, page mapped to the index.aspx.
  5. This approach won't work if you have 100 of pages to map.
  6. Best solution is to use regular expressions, but ASP.NET does not support. SEE
    URL Rewriting

Custom ASP.NET Error Pages
  1. Open web.config file. (see MSDN)
  2. Modify/Create the <customErrors> section within the system.web section.
  3. <customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
    <error statusCode="404" redirect="FileNotFound.htm" />
    <error statusCode="403" redirect="~/errors/NoAccess.htm" />
    </customErrors>
  4. redirect url may be relative(~/errors/PageNotFount.aspx) or absolute (http://makdns.blogspot.com/errors/PageNotFount.aspx)
  5. ~ point to the root of your web application


Custom Non-ASP.NET Error Pages (HTML, ASP,..)
  1. Open the Internet Services Manager.
  2. Expand your Default Web Site.
  3. Right-click and select Properties.
  4. Click the Custom Errors tab.
  5. Scroll down and highlight the 404 HTTP error and click Edit Properties.
  6. Change Message Type to URL.
  7. Enter the URL to "/FileNotFound.aspx".
  8. Click OK.

No comments:

Post a Comment