Reputation: 8868
I have notice that stackoverflow.com does not have file extensions on their pages. How would I do this with an aspx web site?
Upvotes: 6
Views: 2230
Reputation: 1404
If you still want to use ASP.Net without going the MVC route (MVC is awesome, btw) you can route requests using a HTTP Handler.
http://msdn.microsoft.com/en-us/library/ms227675(v=vs.100).aspx
Upvotes: 0
Reputation: 1684
The URLs aren't actually pointing to files. They're using URL rewrite rules to convert the URL to a database query and feed the output back to a specified page (whose URL isn't displayed).
Edit: For clarification SO uses MVC, so the url is pointing to a specific controller action (with or without parameters, depending on the page). The action runs some code to grab data or whatever and passes it to a corresponding view, which is basically an html template that fills in the info provided by the action and renders the page.
Upvotes: 6
Reputation: 6734
As a few people have mentioned, SO is using the URL routing engine included with MVC. They've actually made the code available via CodePlex, so you can use it inside of a webforms-based ASP.NET site.
Phil Haack has a nice summary of how to do this:
It includes samples, links, etc. that should be helpful in getting you started.
Upvotes: 2
Reputation: 2278
Stack Overflow uses ASP.NET MVC which does clean URLs out of the box.
Basically what you need is something that takes the clean URL and then maps it to a standard .NET URL with your passing in extra 'directories' as parameters. e.g. rewriting /blog/post-no-one to /blog.aspx?id=post-no-one.
The new IIS has a rewrite plug in that will do this for you if you want to do it with traditional ASP.NET:
Or you can roll your own by overriding HttpModule and doing rewrites in there. Here is a complex example of that:
Upvotes: 5
Reputation: 21178
Here's a great article from Scott Guthrie:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
It covers off all scenarios: IIS 6, IIS7, using third party URL rewriting tools, etc.
Upvotes: 7