Microsoft KB Archive/267883

= IIS 5.0 URLEncodes URLs passed to Response.Redirect =

Article ID: 267883

Article Last Modified on 10/18/2005

-

APPLIES TO


 * Microsoft Active Server Pages 4.0, when used with:
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q267883



SYMPTOMS
When you view an Active Server Pages (ASP) page that uses the server-side Response.Redirect method in a Web browser, you may receive the following error message:

HTTP 404 - File not found

Internet Information Services

Note The ASP page works fine when it is hosted on Internet Information Server 4.0, but when the page is hosted on Internet Information Services 5.0, the error occurs.



CAUSE
The Response.Redirect method takes one argument (a string) that causes the browser to attempt a connection to a different Uniform Resource Locator (URL). Under Internet Information Services 5.0 the URL is encoded, but on Internet Information Server 4.0 it is not encoded. The error that is described in the &quot;Symptoms&quot; section usually occurs because the string that is passed to the Response.Redirect method is already URL-encoded. Internet Information Services 5.0 takes the encoded string and then encodes the string a second time, thus resulting in a URL that does not exist.

For example, the following code sample attempts to redirect to a file that is named &quot;Page,One.asp&quot;, in which the file name has been URL-encoded: Response.Redirect(&quot;Page%2COne%2Easp&quot;) If the page is hosted on Internet Information Services 5.0, the Response.Redirect method sends a message to the browser to request the new URL that has been encoded a second time. The requested file name is now incorrect, as in the example shown in the resolution section: Page%252COne%252Easp Because &quot;Page%252COne%252Easp&quot; does not exist on the server, the browser will receive the &quot;HTTP 404 - File Not Found&quot; response.

Note You may see unexpected behavior from Internet Information Services 5.0 if you use the Response.Redirect method together with either the UrlEncode method or the UrlPathEncode method.



RESOLUTION
To resolve this problem, you can test to see which version of Internet Information Server/Services is being used and then use the Microsoft JScript unescape function in your code if necessary. When you use the unescape function, all characters that are encoded with the %xx hexadecimal form are replaced by their ASCII character set equivalents. Here is an example:  strIISVersion = Request.ServerVariables(&quot;SERVER_SOFTWARE&quot;) If (strIISVersion = &quot;Microsoft-IIS/4.0&quot;) Then Response.Redirect &quot;Page%2COne%2Easp&quot; Else Response.Redirect unescape(&quot;Page%2COne%2Easp&quot;) End If  Additionally, you can use the following script to manually encode the URL if the server is Internet Information Server 4.0 and leave it un-encoded if the server is Internet Information Server 5.0 (5.0 encodes it automatically):  strIISVersion = Request.ServerVariables(&quot;SERVER_SOFTWARE&quot;) If (strIISVersion = &quot;Microsoft-IIS/4.0&quot;) Then Response.Redirect Server.URLEncode(&quot;Page,One.asp&quot;) Else Response.Redirect &quot;Page,One.asp&quot; End If 

Keywords: kbscript kbwebserver kbaspobj kbprb KB267883

-

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

© Microsoft Corporation. All rights reserved.