Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewriting URLs in ASP.NET?

I am using ASP.NET C#.

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

http://stackoverflow.com/questions/358630/how-to-search-date-in-sql

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:

http://myweb.com/showdetails.aspx?id=9872

But I'd like them to appear like:

http://myweb.com/showdetails/9872/my_question_title

Or:

http://myweb.com/9872/my_question_title

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.

like image 212
djmzfKnm Avatar asked Feb 06 '09 17:02

djmzfKnm


People also ask

What is URL rewriting explain with example?

Url rewriting is a process of appending or modifying any url structure while loading a page. The request made by client is always a new request and the server can not identify whether the current request is send by a new client or the previous same client.

What is rewrite URL in IIS?

About the URL Rewrite module The Microsoft URL Rewrite Module 2.0 for IIS 7 and above enables IIS administrators to create powerful customized rules to map request URLs to friendly URLs that are easier for users to remember and easier for search engines to find.

What is the difference between routing and URL rewriting?

URL rewriting is focused on mapping one URL (new url) to another URL (old url) while routing is focused on mapping a URL to a resource. Actually, URL rewriting rewrites your old url to new one while routing never rewrite your old url to new one but it map to the original route.


1 Answers

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).

like image 96
Franci Penov Avatar answered Sep 30 '22 07:09

Franci Penov