views:

330

answers:

5

Mentioned stackoverflow only as an example, but if you look above the URL for ask is

http://stackoverflow.com/questions/ask

which means /ask is a subdirectory, but they also do this for the specific question pages. How do you code this in .NET?

Not a code question as much as a technique. I know this is great for SEO, but how do you create a site so that every "page" is its own directory? Dynamically.

Do you have a template or a hidden redirect???

How?? :)

+10  A: 

It's termed URL rewriting:

Url Rewriting with ASP.NET

MSDN: URL Rewriting in ASP.NET

EDIT: As @Justice points out, StackOverflow uses Routing.

Mitch Wheat
If you are going to downvote, how about leaving a comment as to why?
Mitch Wheat
I up voted since you are the only one with the right answer
Matt Briggs
I've upvoted you too. What is with those stupid answers about what SO was build with? Your answer directly answers the questions.
mezoid
Thanks so much... those two articles are great.
peiklk
Argh... my hosted server is only on IIS6 still... and I don't have access to install an ISAPI filter.
peiklk
another downvote, many months after answer, again with no comment!
Mitch Wheat
+1  A: 

Stack Overflow uses ASP.net MVC

MVC uses the URL + Query String to determine the content, so its not like a URL which points to a specific page, but more like a hierarchical path to the properties of some data to be displayed

E.G. http://stackoverflow.com/users/[Put User ID Here]/[Put User Name Here]

prompts the website to display a USER with an ID specified in the path ( in this case the user name is probably just for kicks ) as opposed to a specific page created just for that user.

TJB
The poster wasn't asking what SO was written in.
Mitch Wheat
+5  A: 

Stack Overflow was built using ASP.NET MVC which uses a technique called Routing, see:

What Was Stack Overflow Built With?

and Routing

mundeep
-1 You completely missed the point of the question. He didn't ask how SO was build...infact it is specifically stated that SO is only used as an example. His question is about how to rewrite the url to appear as though it is a directory...and the only correct answer so far is from Mitch.
mezoid
OK so my response isn't as complete as Mitch's and doesn't specifically mention Routing as per Justice's however it still answers the question on how to (atleast one way) "create a site so that every "page" is its own directory"
mundeep
+6  A: 

StackOverflow uses something called Routing, which comes with .NET 3.5 SP1. Routing is a popular feature of a number of MVC frameworks, such as ASP.NET MVC, Ruby on Rails, and a number of Python and PHP frameworks.

Justice
+1  A: 

I have seen this accomplished by simply creating a folder for every web page and then having each folder contain a Default.aspx document (Assuming Default.aspx is setup as a default document in IIS, which it is by default). Then you can navigate to any folder on the site without specifying the page (Default.aspx).

For the dynamic part, I have worked with CMS systems that do it this way and the Default.aspx page simply inherits from some master template and the CMS system utilizes the ASP.NET rendering enginge to dynamically complete the web page.

Using folders may be a little heavy with the site structure, but it is an easy way to eliminate the page names from the browser.

This is how I structure my website and avoid having to use page names... for example http://www.innovaapps.net/Blog simply brings up the default.aspx page without having to specify the page name.

Bryan Sebastian