vote up 0 vote down star

I am using ASP.NET 2.0 on IIS6 therefore I can’t use system.web.routing. I’ve tried a few URL rewriters but none did what I wanted.

I basically need to transform (read/parse then redirect) URL 1 into 2 with minimum IIS configuration because I don't have the full authority to reconfigure web servers (i.e. ISAP on IIS6 or install 3rd party extensions/libraries). And I can’t transform URL into 3 because all the physical links will break.

  1. http://www.url.com/abc123
  2. http://www.url.com/default.aspx?code=abc123
  3. http://www.url.com/abc123/default.aspx?code=abc123

Thank you!

flag

3 Answers

vote up 1 vote down check

Create 404 error handler, e.g. 404.aspx. In that page, parse request URL and extract code using Request.Path. Then, redirect to default.aspx?code=abc123.

You should be able to set 404 (page not found) handler to 404.aspx for your website, most hosting providers allow that.

link|flag
I was going to manually do the parsing and redirect in Application_Error (global.asax) because I couldn't get rid of the aspxerrorpath querry string as I can't capture the value of /abc123 before aspxerrorpath is thrown because Request.Path is alwasy the URL of the 404 error page. – Jeffrey Jan 14 at 3:51
Make sure you set 404 handler in IIS, not in web.config. – Pavel Chuchuva Jan 14 at 4:08
Do you recommend Application_Error (global.asax) than 404? Becuase I don't have too much control over web servers and we have more than 1 web servers so I prefer the "soft" way. For any IIS setting change, it takes weeks to get approved... – Jeffrey Jan 14 at 4:16
If you get Application_Error event for extension-less URLs like http://www.url.com/abc123 by all means, use it. Otherwise you need to configure IIS to use your 404 handler. – Pavel Chuchuva Jan 14 at 21:39
I've configured my dev IIS to forward 404 to my 404 page yet Request.Url and Request.Path both showing the path to 404 page and Request.UrlReferrer is null. – Jeffrey Jan 14 at 23:29
show 4 more comments
vote up 0 vote down

I would suggest that you look at using a custom transform with UrlRewriter.net. This link details how you can do it with the Intelligencia.UrlRewriter assembly (about 3/4 of the way down the page). Hopefully is good enough to do what you need.

link|flag
I don't think URL rewrite will work because I don't want the URL to be rewritten I only need the URL to be read/parsed then redirect. – Jeffrey Jan 14 at 1:13
vote up 0 vote down
protected void Page_Load(object sender, EventArgs e)
{
    HtmlLink canonicalTag = new HtmlLink();
    canonicalTag.Href = "http://www.url.com/default.aspx";
    canonicalTag.Attributes["rel"] = "canonical";
    Page.Header.Controls.Add(canonicalTag);
}

http://codersbarn.com/post/2009/02/21/ASPNET-SEO-and-the-Canonical-Tag.aspx

link|flag

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.