2

I've a site, we are using ASP.NET 4.0, and right now our products content is managed like this

www.franko1.com/products.aspx?serie=2000

where the querystring serie is the product ID, so its value is taken and then the contents is extracted from the database.

Now for SEO reasons, we've been asked to change the urls, so now they have to look like this:

What the boss want                    | Current Urls
--------------------------------------------------------------------------------
www.franko1.com/Relief_Valves         | www.franko1.com/products.aspx?serie=2000
www.franko1.com/Inline_Flame_Arrester | www.franko1.com/products.aspx?serie=1000
www.franko1.com/Vent_Hatch            | www.franko1.com/products.aspx?serie=3000

and so on ...

Right now, we are using a masterpage and the products.aspx and as I said, we take the querystring serie and we show the content based on its value, I have no idea how to do this using asp.net, I have read about ISAPI_Rewrite but I was wondering if there is a technique to approach this without dealing with the IIS server....

Well I don't know if I was clear, It is hard to explain,

4
  • I'm assuming that you can take "Relief_Valves" and get all of the info you need from the DB out of it, yes? You just need to know how to map that to www.franko1.com/somepage.aspx?someParam=Relief_Valves? Commented Aug 23, 2012 at 18:17
  • 2
    I think it would be much easier to do www.franko1.com/products/Relief_Valves. Check out url routing. Commented Aug 23, 2012 at 18:17
  • URL Re-writing rules can be written in web.config without any changes in IIS Commented Aug 23, 2012 at 18:17
  • Routing using global.asax could be your solution: stackoverflow.com/questions/11704745/… Commented Aug 23, 2012 at 18:19

2 Answers 2

4

No need for that. You can achieve this via routing (It's not just for MVC).

Routing has been available as a stand alone module for a while now, but with ASP.Net 4.0 you can now use routing for WebForms just as easily as you can with MVC.

You will need to add some routing to your Global.asax

public class Global : System.Web.HttpApplication
{

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterRoutes(RouteCollection routeCollection)
    {
        routeCollection.MapPageRoute("Products", "Products/{Name}", "~/Products.aspx");
    }

}

And with that you can now reference the route values in your page like so:

protected void Page_Load(object sender, EventArgs e)
{
    string prodName = Page.RouteData.Values["Name"].ToString();

    //Do lookup, etc...
}

Your URLs will end up looking like this:

www.domain.com/products/Relief_Valves
www.domain.com/products/Widgets
www.domain.com/products/TrashCans

etc..

Nice and easy... and clean!

Sign up to request clarification or add additional context in comments.

Comments

0

URL rewriting was made just for exactly this purpose. The problem is that it really doesn't work with variable content directly appended to the root URL. There really isn't enough information for URL routing to separate such URLs from the rest of your URLs.

Would your boss accept www.franko1.com/p/Relief_Valves ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.