开发者

How to transform ASP.NET URL without URL routing or URL rewrite?

开发者 https://www.devze.com 2022-12-16 20:57 出处:网络
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 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 n开发者_JS百科eed 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!


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消