Url rewriting problem associated with trace tag in web.config RRS feed

  • Question

  • User-428563227 posted
    I've just started using url rewriting but I'm having problems with Asp.Net not being able to find the page I'm rewriting to. I'm using an HTTP module to catch the request. The class it calls determines what page it should redirect to and rewrites the path. It works fine for a while but after a few requests I get an HTTP 404 error saying the rewritten page cannot be found. So /friendlypage.aspx rewrites to /unfriendlypage.aspx. The error will say it couldn't find the unfriendly page even though it definitely exists and it has been able to find it previously. After using the Trace functionality to try and debug the problem I found that if the requestLimit attribute of the trace tag in the web.config file was set to 10 then I would get 10 good rewrites then the 11th would error. If I changed the requestLimit to 20 then I would get 20 good rewrites before the 21st returned a 404 error. If I turn tracing off then the rewriting stops working altogether! This happens on dev box (Win XP) and staging server (Win 2K). Has anybody come across this problem before or have any ideas? Thanks.
    Sunday, February 20, 2005 1:29 PM

All replies

  • User-428563227 posted
    Fixed the problem. Before calling RewritePath() I was accessing the HttpContext.Current.Request.QueryString collection to check if anything was on the query string. For some reason this was causing the issue described in my previous posts. I rewrote this line by accessing it through HttpContext.Current.Request.ServerVariables("QUERY_STRING") and the rewriting works fine.
    Sunday, February 20, 2005 7:59 PM
  • User948010097 posted
    OH MY GOD! I love you!

    I have been having this same problem all night and I never figured it out. I completely re-wrote my HttpModule after authoring a new flow diagram ( http://www.flickr.com/photos/elusivebyte/9172450/ :) ) It was good to clean up the code, and I figured I had scrubbed the bug out in the process, but then it was still there! I screamed out loud! I'd been pulling my hair out for hours!

    To tell the truth I didn't have much hope when I read your fix, but it worked! WHAT does the usage of the QueryString collection have to do with url rewriting?  I had a check for QueryString["path"]. I didn't even care what the value was. I was only checking for null. Now I used a Regex to see if it's in the raw QueryString and the error went away. I'm not using the ServerVariables though. I'm using HttpContext.Current.Request.Url.Query.

    My module handles all requests by adding the wildcard, ".*", to IIS mapped to Asp.Net. From your example, it looks like you were just rewriting aspx pages to other aspx pages. Is that the case? Also, I turned off tracing and my rewriting still works fine.

    Thank you so much for posting your fix! I owe you a beer... or ten!

    - Todd

    Tuesday, April 12, 2005 12:29 AM
  • User948010097 posted

    I was able to reproduce the "Url rewriting doesn't work at all when Trace is off" error by moving my url rewriting into the AuthorizeRequest event handler. But is still stops after 10 requests even if I have Trace enabled. I was originally using BeginRequest, but then I read Scott Mitchels article stating how that doesn't work well with Forms authentication. I guess I'll go back to BeginRequest and see if I have any problems with authentication.

    What event are you using, and, if you are using AuthorizeRequest, how come it works for you?

    - Todd

    Tuesday, April 12, 2005 1:30 AM
  • User-428563227 posted

    Hi ,yeah, I was just rewriting aspx to aspx pages.  I've never tried using forms authentication with Url rewriting so haven't experienced any of those issues.  I was doing the rewriting in the BeginRequest method.

    Glad I could be of help!

    Tuesday, April 12, 2005 10:35 PM