URL rewriting .net 1.1 RRS feed

  • Question

  • User1161379405 posted

    I'm trying to implement url rewriting in an old project written in .net 1.1.  I've found several forums talking about url rewriting in .net 2.0, but nothing that is very helpful for 1.1.  I've got the basic functionality working - I am able to link to www.mypage.com/folder/info and it redirects to the correct page.  The problem I am having is that it breaks the relative links on all the pages.  Links that pointed to "~/page1.aspx" now link to www.mypage.com/folder/page1.aspx instead of the correct url www.mypage.com/page1.aspx.  I've found a few pages that say to use the HttpContext.RewriteUrl() method in the Page_PreInit method of the target page, but there is no PreInit method in .net 1.1.  I've tried adding the RewriteUrl code to the Init method but that too doens't seem to work.  If anyone has an example of successfully implementing url rewriting in .net 1.1, I would really appreciate it!


    Monday, April 9, 2007 11:25 AM

All replies

  • User-1391363652 posted
    URL rewriting in 2.0 is pretty much useless, so you're not missing much. One way to do it in 1.1 is to write redirection by hand. Scott Mitchell wrote an article on MSDN a while ago. To avoid the hassle, you can use a couple of free components. Another Scott wrote a blog post on this subject just recently.
    Monday, April 9, 2007 1:06 PM
  • User1161379405 posted
    I've read the article on msdn and he makes no mention of relative links.  My code works pretty much just like his but I don't use rules.
    Monday, April 9, 2007 4:16 PM
  • User1161379405 posted

    Just in case anyone else is looking for an answer to this problem..

    One possible solution to this problem is to loop recursively through all the controls on the page and call Page.ResolveUrl("~/page1.aspx").  That fixes the urls of all the asp controls on the page, but if you have any html controls on your page or you're using css stylesheets, those links are still broken.  It can also slow your page considerably depending on how deep you allow the recursion to go.  I wasn't able to use this solution because of the complexity of some of my pages, but it could work on a simple page.  The solution I ended up having to use was to just remove the extra directory and redirect to www.mypage.com/folder-page1.aspx

    Monday, April 23, 2007 12:49 PM
  • User-225114762 posted

    See my long entry in the thread http://forums.asp.net/thread/1661626.aspx . It's about a different issue, but the main part of the post explains the problem with the naive style of implementing URL rewriting - just rewriting incoming. To get it to work properly you need to rewrite outgoing HTML as well. The fact that it does appear to work somewhat using just rewrites of incoming URL's doesn't change this fact - it just appears to work in some very special cases.

    The long and short of it is - if you want URL rewriting to really work, you need to write yourself a filter for the outgoing HTML and fixup that as well.

    Monday, April 23, 2007 2:59 PM