How to transform ASP.NET URL without URL routing or URL rewrite?
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.
- http://www.url.com/abc123
- http://www.url.com/default.aspx?code=abc123
- 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
精彩评论