RewritePath Issue RRS feed

  • Question

  • User-586119434 posted
    Hi Guys... I use the RewritePath method to rewrite the internal path within the Application_BeginRerquest Event in the Global.asa file, so if the user request a page like http://localhost/main/level1/level2/level3/99.aspx would be rewritten as http://localhost/main/process.aspx?id=99 It seems like it's working fine but the problem is when the path is rewritten, it mess up all the links and images references in the process.aspx page... like for instance, an image that should be referened as http://localhost/main/images/image1, it would be rewritten as http://localhost/main/level1/level2/level3/images/image1 .... So for some reason the RewritePath method makes the process.aspx page act like its root is http://localhost/main/level1/level2/level3. Is there a solutions for this? ... here is my code Dim incoming As HttpContext = HttpContext.Current Dim oldpath As String = incoming.Request.Path.ToLower() Dim strCustomPath As String Dim Makeid As String Dim Modelid As String Dim URLKey_makes As String = "/auto-sale/make/" 'look for make id in the url If InStr(oldpath, URLKey_makes) > 0 Then Dim regex As Regex regex = New Regex("(\d+).aspx", RegexOptions.IgnoreCase) Dim matches As MatchCollection matches = regex.Matches(oldpath) If matches.Count > 0 Then 'Extract the make id and send it to Process.aspx Makeid = matches(0).Groups(1).ToString() If Request.ApplicationPath = "/" Then strCustomPath = String.Format("/Process.aspx?makeid={0}", Makeid) Else strCustomPath = String.Format("{0}/Process.aspx?makeid={1}", Request.ApplicationPath, Makeid) End If 'incoming.RewritePath(strCustomPath) End If End If
    Saturday, March 20, 2004 10:13 PM

All replies

  • User-1391363652 posted
    Technically the browser doesn't know that the underlying URL changed so,quite naturally, the relative images paths will get messed up. I always recommend using full paths in the src attribute to prevent this predicament from happening. Or... you may call Response.Redirect instead of RewritePath to let the browser know that the location of the page changed. Response.Redirect sends a 302 HTTP code and causes a round trip to the server, though.
    Saturday, March 20, 2004 11:09 PM
  • User-586119434 posted
    that makes sense... when I reference the images, in a header and footer controls.. I use "~" so the image path always starts from the application root.. for ex "~/images/farleft.jpg" ... I can't use the response.redirect as I'm trying to trick Search Engines, and it doesn't like redirects. well, I'm out of ideas as of 11:30 pm on saturday which is pretty natural...:)
    Saturday, March 20, 2004 11:26 PM