views:

218

answers:

5

Objective was:

To change pages like details.aspx?GUID=903901823908129038 to clean ones like /adrian_seo

Achieved: Now using Response.AddHeader("Location", url);

I am able to remove all uppercase urls. I use the following function:

protected void Page_Load(object sender, EventArgs e)
{
    string url = Request.Url.ToString();
    if (url != Request.Url.ToString().ToLower())
    {
        url = Request.Url.ToString().ToLower();
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location", url);
    }
}

Question is:

How do I change these to clean urls like /adrian_seo

I mean how do I handle requests coming to /adrian_seo and how do I show my old pages with new urls.

Do I need to use Global.asax?

+6  A: 

Have a look into ASP.NET routing.

Eric Petroelje
Good suggestion, especially because Routing can be used without ASP.net MVC if desired.
Michael Stum
System.Web.Routing is my new best friend.
Chris
Well it does not solve issue of posting a 301 redirect to client and as far as i understand post its a SEO thing that Arjun is looking for.
Claus Thomsen
He is doing the 301 redirect correctly. If he wants to redirect to a completely new URL, then he would need to maintain a mapping of the old urls to the new urls and use that for the redirect.
Eric Petroelje
Eric, I cannot see how Asp.Net Routing will solve issue of maintaning e.g. pagerank for old url. So in my opinion using Asp.net routing on an existing site will make SEO even worse. For a long term solution i can second eventually substituting a UrlRewrite that issues a 301 with Asp.net Routing.
Claus Thomsen
A: 

You could use http://urlrewriter.net/ which can be used on asp.net 1.1 ->

Claus Thomsen
+1  A: 

Use an HttpModule:

  public void Init(HttpApplication context)
  {
    context.BeginRequest += new EventHandler(context_BeginRequest);
  }

  void context_BeginRequest(object sender, EventArgs e)
  {
    HttpContext context = ((HttpApplication)sender).Context;
    if (context.Request.RawUrl.ToLowerInvariant().Equals("YOURSEOURL"))
      context.RewritePath("YOURNONSEOURL");
  }

Note that you don't want to hard code all this. Find some sort of regex to match your need, like if the SEO url is: /page/234234/This-is-my-page-title, you grab the 234234 and rewrite the path to page.aspx?pageid=234234

UPDATE You can also use the IIS 7 Rewrite Module

MartinHN
+1  A: 

I recommend using the UrlRewritingNet component. When writing your own library you need to overcome some difficulties, this library already handles that stuff for you...

It is a rewrite-module tuned for ASP.NET 2.0, and offers support for

  • Themes and Masterpages
  • Regular Expressions
  • Good Postback-Urls
  • Cookieless Sessions
  • Runs in Shared-Hosting or Medium-Trust enviroments
  • OutputCache is supported
  • Redirects possible, even to other Domains

To enable extenionless urls in asp.net with IIS 6 or lower your also need to configure IIS to let asp.net handle all incoming requests.

Sander Versluys
A: 

After some Read up on Routing in Asp.net:

http://blog.eworldui.net/post/2008/04/ASPNET-MVC---Legacy-Url-Routing.aspx

Which brings both 301 redirects for SEO page rank and Asp.net Routing for permanent organic SEO solution.

Claus Thomsen