James

James

  • NA
  • 1
  • 0

HttpContext.RewritePath issue in Server 2003 only

Jul 20 2005 4:11 AM

Background:

I’m having problems with the HttpContext.RewritePath method. I’ve seen this discussed on other threads; however, I think my problem differs. I’m trying to create a URL Manager to provide so called friendly URLs. I have various restrictions as my site is hosted on a co-locate server. In short I am trying to achieve URLs as below, where none of the directories or files exists:

 

/Products/

/Products/Clothes/

/Products/Clothes/Shirts/

/Products/Clothes/Shirts/Product123.aspx

 

Due to the restrictions on my server I am having IIS redirect HTTP 404 and 405 errors to an ASPX page (/UrlManager.aspx) rather than modifying the application extension mappings in IIS. I then parse the original request path storing details in Context.Items. The requests are then “redirected” using Context.RewritePath to either (respectively):

 

/Section.aspx

/Product.aspx

 

The ASPX file then returns the appropriate page. Handling the 404 errors in this way allows requests for non-existent directories to be received by ASP.NET.

 

This technique works. It works very well on XP Pro with Framework 1.1; however, Windows Server 2003 with Framework 1.1 (either with or without SP 1) has a critical problem. Of course my site is hosted on Server 2003.

 

The Problem (only on Server 2003):

Postback fails for: /Products/Clothes/Shirts/

1)     The Url manager succeeds in rewriting the path to /Section.aspx;

2)     Section.aspx has a populated Request.Form collection;

3)     IsPostBack always equals false;

4)     Request.RequestType always equals GET.

 

Regardless of what has happened on the client, Setion.aspx always thinks the request is a GET.

 

Furthermore, Product.aspx works perfectly. This is interesting as Product.aspx is only called when a request URL of ProductNNN.aspx is received; Setion.aspx is called when no extension is provided (it wouldn’t normally be handled by ASP.NET without amending the application extension mappings).

 

The crux of the problem is that when no ASPX extension is provided, the desired/expected postback functionality on Server 2003 fails; it works perfectly on XP Pro.

 

It should be noted that when serving both Section.aspx and Product.aspx, the Form Action attribute has been amended to point to the friendly URL rather than the originating page.

 

Apologies for the length of this post; however, I wanted to capture as much information as possible in the first instance.

 

Thanks in advance.