次の方法で共有


HTTP_URL Server Variable behaves differently in IIS 5 and 6

 

Issue

====

One of my Customer’s configured an ASP file named *NotFound.asp* to process 404 errors inside the Custom Errors section of Internet Services Manager, where he uses HTTP_URL Property to get the bad page or malformed URL that user has just requested. There he is maintaining two Arrays. First array represents the list of bad/old URL and the second array maps to their latest version available.

Initially the application was developed on IIS 5. Migrating it to IIS 6 started giving problems because of the following reason(s):

He is storing the URL’s in Array as https://machinename/VdirName/Pagename.asp i.e. without PORT information because HTTP_URL doesn’t include the PORT information in IIS 5 or the versions below it.

As soon as he retrieves the Bad page as:

var badPage = Request.ServerVariable(“HTTP_URL”),

He strips off *404;* part from the badPage and queries on the second array to get its newer counterpart. The logic works on IIS 5 but fails on IIS 6 because HTTP_URL now include PORT information even with the default web site running on PORT 80 which he has not handled in the code right now.

Now he is asking whether there is some setting on IIS 6 that specifies not to include the PORT number in the HTTP_URL variable.

Actually there is no such setting in IIS 6 where we can specify not to use PORT number in the return URL. We have to handle this situation only by writing code that will strip off the PORT information from the bad page before any lookup operation. I also tried searching this information on support site as well as visual KB but couldn’t find anything.

WORKAROUND

==========

<%

Function parseUrl(url)

  firstpartlength = instr(6, url,":")-1

  If firstpartlength > 0 Then

   firstpart = mid( url, 1,firstpartlength)

    lastpartindex = instr(firstpartlength, url,"/")

    lastpart = mid(url,lastpartindex)

    url = (firstpart & lastpart)

  End If

  parseUrl= url

End Function

%>

<%= parseUrl("https://machinename:8080/Vdir/BadPage.asp")%>

NOTE:- On IIS 5, even if Default Web site is running on some other PORT instead of PORT 80, HTTP_URL will still not display the URL with a PORT number. It can be considered as a BUG or Limitation on IIS 5.