Last post Apr 23, 2007 02:59 PM by Svante
Apr 09, 2007 11:25 AM|lkuh|LINK
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!
Apr 09, 2007 01:06 PM|MilanNegovan|LINK
Apr 09, 2007 04:16 PM|lkuh|LINK
Apr 23, 2007 12:49 PM|lkuh|LINK
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
Apr 23, 2007 02:59 PM|Svante|LINK
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.