2

I got an issue when using HttpContext.RewritePath in HttpModule for URL rewriting.

Environment: Windows Server 2008 R2, IIS 7.5 integrated mode, .Net 4.0 In my project, most URLs will be rewritten to the same aspx page(Handler.aspx). The aspx page will do different thing based on the URL.

Example:

"/en/abc/" will be written to Handler.aspx. [Page output: This is abc]

"/en/test/" will be written to Handler.aspx. [Page output: This is test]

"/en/test/a.html" will be written to Handler.aspx as well. [Page output: This is test]. As I only check the string "test" and ignore the sting "/a.html", the output is same as the URL "/en/test/". And a.html doesn't exist in wwwroot folder, the URL is a bad case for testing.

I got a issue, if 2 or more requests that contain htm/html extension come simultaneously Example: "/en/test/a.htm" or "/en/test/a.html"

HttpContext.RewritePath will not work for any request after that. Handler.aspx won't be called any more, and the page output will always be 'This is test' no matter what URL entered. Http status code is 200 when the issue occurs. Also if visit the real aspx page(Handler.aspx), it will display the same content 'This is test' as well. It seems like a server-side cache. And this issue can be resolved by recycling app pool in IIS.

In following cases, the issue won't occur:

  1. Visit these two requests with a delay, for example visit "/en/test/a.html" first and wait 3-5 seconds, then visit "en/test/a.html" again. Everything works fine.

  2. Change IIS pipeline from integrated mode to classic mode. If visit "/en/test/a.html", a IIS 404 page will be displayed.

  3. Use Server.Transfer instead of HttpContext.RewritePath, everything works fine.

  4. The URL contains .php, .jsp, .xml won't cause the issue

I have to find the root cause of it. Any potential reason may cause this issue?

4

0 回答 0