1

Ok. I hope it's a right question and title.

I'm totally newbie to asp.net and c#. I've been searching the answer for days and got nothing. So i think this is the best place to ask this question.

this is my current URL

http://localhost:7474/mywebsite/ProductDetails.aspx?Category=CSR&artID=36&alias=support-for-central-jaya-and-yogyakarta-earthquake-disaster

I Want to make search engine friendly url. Can I make above URL to

http://localhost:7474/mywebsite/ProductDetails/CSR/36-support-for-central-jaya-and-yogyakarta-earthquake-disaster

FYI I'm not using MVC.

2
  • What IIS version are you using? Commented Apr 4, 2013 at 3:31
  • @cheesemacfly I'm using IIS version 6.0 Commented Apr 4, 2013 at 6:56

3 Answers 3

2

Yes, you can.

Take a look at RouteCollection.MapPageRoute for details but roughly you need the code below:

routes.MapPageRoute(
    "ProductDetails",
    "/ProductDetails/{Category}/{artID}/{alias}",
    "~/ProductDetails.aspx");

However artId and alias cannot be in the same segment. They need to be separated by a slash (/).

The other difference is that you need to grab the parameter values from RouteData instead of querystring so instead of:

Request.QueryString["Category"]

you do:

Page.RouteData.Values["Category"]

ps: I did it from the top of my mind so it might not compile

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

3 Comments

thanks for fast response. I'll try your code and let you know if that's work for me.
I think i can't use your code because my version is .NET 3.5 :(. Maybe you have another suggestion?
Hmmm.... What you probably don't have in 3.5 is the MapPageRoute extension method of RouteCollection. However, it should be possible to download the aspnetwebstack, see how it is implemented and do it yourself. The necessary infrastructure for routing is there, you just need to wire it up to make it work. I suggest you study how to implement custom route handlers.
1

May be you can try URL Rewriting. That would be an ideal choice to implement this with no code change at all. And use regular expression to extract values from the url to bounce the values to original aspx page.

http://www.iis.net/downloads/microsoft/url-rewrite

Comments

0

Yes, we can create search engine friendly URL using ASP.NET routing feature. This blog post have an example of URL routing - http://newapputil.blogspot.in/2013/12/aspnet-40-web-forms-url-routing.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.