Take the 2-minute tour ×

I am using ASP.NET C#.

How do I implement URL re-writing procedure that is similar to StackOverflow.com?


Also, what is the meaning of values such as "358630" in the URL? Is this the question ID (the basis for which they use to fetch the data from the table)? Whatever it is, in my application I am identifying records using an "ID" field. This field is an identity column in an SQL table. Right now, my URLs are like the following:


But I'd like them to appear like:




Or whatever the best way, which will taste good to search bots.

My application is hosted on Go Daddy's shared hosting service, and I feel that no customized ASP.NET "HTTP module" or no customized DLL for URL re-writing is working on their server. I tried many samples but no luck yet!

I found that Stack Overflow is hosted on Go Daddy (shared hosting?). Maybe Stack Overflow's method will work for me.

share|improve this question
Not sure why this was down voted. Seems like a legitimate question to me. –  Spencer Ruport Feb 6 '09 at 17:44
Yes, this is a perfectly legitimate question. –  BobbyShaftoe Feb 6 '09 at 17:45
drive by downvoters. Sheesh. They don't have the balls to say WHY. –  Will Feb 6 '09 at 17:46
I guess some 1337 guy w/ RTFM attitude was offended that Prashant hasn't heard about ASP.NET MVC. :-) –  Franci Penov Feb 6 '09 at 17:46
"Tastes good to search bots." Love it. –  Tom Feb 6 '09 at 18:18
show 1 more comment

5 Answers

up vote 12 down vote accepted

SO is using ASP.NET MVC. You really need to read in details how MVC URL rewriting works, but the gist of it is that the 'questions' part in the URL is the name of the Controller class (which roughly corresponds to the 'showdetails' in your URL) and the number is a ID parameter for the default action on that Controller (same as the parameter 'id' in your URL).

share|improve this answer
I am using ASP.NET 2.0 (C#) can I use ASP.NET MVC to develop my applications? Or I require ASP.NET 3.x+ to use ASP.NET MVC ? –  Prashant Feb 6 '09 at 17:56
Got the answer, it will only work with ASP.NET 3.x+ versions :( microsoft.com/downloads/… –  Prashant Feb 6 '09 at 18:00
Actually, you should check with your hosting service. Most companies that offer .Net 2.0 SP1 also usually offer .Net 3.5 as well, seeing how the CLR is the same and the latter only adds more classes to the framework. –  Franci Penov Feb 6 '09 at 18:53
add comment

Since MVC isn't an option you can try redirecting the 404s. This will work in ASP.NET 1.1 and above: Redirect 404s and 405s to your own handler using either IIS config or web.config, parse out the request in the handler and redirect to the appropriate resource.

    	<error statusCode="404" redirect="newHandler.aspx"/>
share|improve this answer
Man, that's a hackish way of doing it.... there's no side-effects from doing this? –  Lloyd Cotten Feb 6 '09 at 19:07
Used to do this for smaller sites in classic ASP, egh. –  Sciolist Feb 6 '09 at 19:14
Read the requirements. Tastes good to search engines, supported by ASP.NET 2.0, and works on a shared hosting. Do you have a less hackish" solution that fits the reqs? –  xcud Feb 6 '09 at 19:29
I'm not sure this would taste good to search engines - wouldn't the IIS send back status 404? –  Dominic Rodger May 5 '09 at 10:39
add comment

Before the advent of System.Web.Routing, the common practice was to use UrlRewriter.NET. Worked well enough, but could bite you when configuring IIS. I'm not sure if there are any simple ways of using the new Routing classes in ASP.NET (i.e., drop it in and go vs. refactoring code).

share|improve this answer
I can't use this because, UrlRewriter.NET requires installation in IIS, and as I am on shared hosting, so I don't have right to do so :(( –  Prashant Feb 6 '09 at 18:10
That's too bad... Some shared hosting providers offer it as an option; you might want to check with them. –  Will Feb 9 '09 at 11:33
add comment

please explain the meaning of values such as "358630" in the URL

That is (presumably) the ID for the question in the database. In the MVC model


is analogous to


The question title on the end of the URL is actually being ignored by the app. It's generally "tacked on" for search engine optimization and human readability purposes. In fact, you can change the title of this question in the URL and notice the page still loads just fine.

share|improve this answer
Yes, but with "ID" what I understand is if I'll increment +1 in this stackoverflow.com/questions/521310/… url then it should open the next question withour changing other part of the url... –  Prashant Feb 6 '09 at 19:02
But its forwarding me to this stackoverflow.com/questions/521298/when-to-use-struct-in-c/… URL, how StackOverflow is maintaining this??? –  Prashant Feb 6 '09 at 19:02
I can only speculate, but perhaps they're redirecting to a more canonical answer in some instances. So for example, when you type in ID 521311, it redirects to 521298. So you can assume 521298 is the best answer on structs in C#. –  Cory House Feb 6 '09 at 20:51
Perhaps questions and answers (and possibly comments) are all stored in the same table, with some discriminator column(s) to define the type/parent etc - I see that the answer that is referenced with a +1 to the id was left about the same time as your question. –  Zhaph - Ben Duguid Feb 6 '09 at 22:35
It's fairly common in CMS's to store all content in one table, so I don't see why SO isn't doing the same. –  Zhaph - Ben Duguid Feb 6 '09 at 22:36
add comment

The new System.Web.Routing dll is part of ASP.NET 3.5 SP1, and is bin deployable on ASP.NET 3.5, so you could use the features of that on a classic ASP.NET WebForms site.

You'll probably want to take note of Phil Haack's comments in his post on using MVC on IIS 6 as you'll probably need to include the .aspx extension in your routed urls


You might also want to check out Questions Tagged SEO.

The ignored question name at the end of the url is often called a "Slug", and is used for SEO purposes to include the page title in the url.

share|improve this answer
add comment

Your Answer


