Microsoft KB Archive/902239

= Users are not redirected to the page that contains the custom error message when you design an application that uses impersonation in ASP.NET =

Article ID: 902239

Article Last Modified on 6/13/2005

-

APPLIES TO


 * Microsoft ASP.NET 1.1

-





SYMPTOMS
When you design an application that uses impersonation in Microsoft ASP.NET, users are not redirected to the page that contains the custom error message.

You implement impersonation by using the following code.   This problem occurs when you use the following code in the Web.config file.   



WORKAROUND
To work around this problem, redirect to the custom error page by using the following code in the Global.asax file. Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' This exception is raised when an error occurs. Dim ex As Exception = Server.GetLastError.GetBaseException

If ex.GetType Is Type.GetType(&quot;System.UnauthorizedAccessException&quot;) Then Server.ClearError Response.Redirect(&quot;unauthorized.htm&quot;) End If End Sub



Steps to reproduce the problem
 Create a virtual directory. Set the virtual directory to use Integrated Microsoft Windows Authentication. Create a sample .aspx file that contains server side code. Name the file Sample.aspx. Put the file in the virtual directory that you created in step 1. For all accounts except the ASPNET account, deny NTFS file system permissions on the Sample.aspx file.  Create a Web.config file that uses the following code. Put the file in the virtual directory that you created in step 1.  <error statusCode=&quot;401&quot; redirect=&quot;unauthorized.htm&quot; /> </customErrors>

<authentication mode=&quot;Windows&quot; /> <identity impersonate=&quot;true&quot; userName=&quot;Domain\User&quot; password=&quot;Password&quot;/> </li> Create an HTML file that contains custom text. Name the file Unauthorized.htm. Put the file in the virtual directory that you created in step 1.</li> In a browser, view the Sample.aspx file. You are not redirected to the Unauthorized.htm file.</li></ol>

Keywords: kbtshoot kbprb KB902239

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.