Print View

How to configure a custom 404 error for IIS6 and ASP.Net to redirect to a login page

Issue

Web updating a website, particularly one based on third party products the login page URL may change. This can be an issue as users may have bookmarked the complete login URL.

Configuring a custom 404 error page that send users to the new login page can resolve the issue.

IIS6 and ASP.Net both have different mechanisms for setting 404 custom errors.

Resolution

1) Create the custom redirection page
Save this file as redirect.html in the web server root (C:\InetPub\WWWRoot)

<html>
<head>
<title>The Ether: Custom Redirect</title>
<META http-equiv="refresh" content="0;URL=https://domain.com/login.aspx">
</head>
<body>
<!-- Pad the file to greater than 512 bytes to bypass the "Show Friendly HTTP Error Messages" -->
<!-- HOW TO: Turn Off the Internet Explorer 5.x and 6.x "Show Friendly HTTP Error Messages" Feature on the Server Side  -->
<!-- http://support.microsoft.com/kb/294807 -->
<!--When you access Web pages from Internet Explorer 5.x and Internet Explorer 6.x, the actual text of an HTTP 500 message that is sent to the browser may be masked by an Internet Explorer "friendly" error message. Although you can turn off this feature manually for each client, this article also provides several server-side workarounds to inhibit the display of "friendly" error messages. -->
<!-- Several frequently-seen status codes have "friendly" error messages that Internet Explorer 5.x displays and that effectively mask the actual text message that the server sends. However, these "friendly" error messages are only displayed if the response that is sent to the client is less than a specified threshold. For example, to see the exact text of an HTTP 500 response, the content length must be greater than or equal to 512 bytes. -->
</body>
</html>


2) Configure IIS to use the redirect as the 404 custom error
Either save the above file as C:\WINDOWS\help\iisHelp\common\404b.htm or from IIS Manager:

- Expand Local Computer
- Expand Websites
- Right click on Default Web Site and select Properties from the context menu
- Select the Custom Errors tab
- Select 404 and click Edit
- Enter the URL of the redirect page (C:\InetPub\WWWRoot\redirect.html) and click OK
- Select 404;2 and click Edit
- Enter the URL of the redirect page (C:\InetPub\WWWRoot\redirect.html) and click OK
- Select 404;3 and click Edit
- Enter the URL of the redirect page (C:\InetPub\WWWRoot\redirect.html) and click OK
- Click OK to exit Custom Errors

3) Configure ASP.Net to use the redirect as the 404 custom error
Save this file as web.config in the web server root (C:\InetPub\WWWRoot)

<?xml version="1.0" encoding="utf-8"?>
<!-- A URL starting with a tilde (~), such as ~/redirect.html, indicates that the specified URL is relative to the root path of the application. -->
<configuration>
   <system.web>
        <customErrors mode="On">
            <error statusCode="404" redirect="~/redirect.html" />
        </customErrors>
    </system.web>
</configuration>

References

HOW TO: Turn Off the Internet Explorer 5.x and 6.x "Show Friendly HTTP Error Messages" Feature on the Server Side
http://support.microsoft.com/kb/294807

You receive a default error message when you set custom errors in a Web application that is built on the .NET Framework
http://support.microsoft.com/kb/910434

customErrors Element (ASP.NET Settings Schema)
http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx

Products

Microsoft Internet Information Services 6.0
Citrix Web Interface 4.6
Citrix Web Interface 4.2
Citrix Secure Gateway 3.0

Created: 7th May 2008
Updated: 7th May 2008

Print View

© 2005-2024 Jamie Morrison