9

When a question is posted on Stack Overflow what happens?

Does Stack Overflow create a new page with the title of question? If it does then how can this be done in Asp.Net 3.5, C#?

I want to know because I am also creating this type of website for my college project.

6
  • 3
    @paxdiablo that is not a meta question - it is a programming question Sep 1, 2011 at 8:30
  • @Marc, not sure how this is any different to any of the other "how does SO work?" variants that were nudged across. But, it appears you have used that blue diamond to back out the vote. So much for a community-driven site :-)
    – user14860
    Sep 1, 2011 at 8:34
  • 2
    @paxdiablo the question isn't really relating to the SE engine - it relates to a programming technique with SE simply as the example. If other questions have been migrated similarly, they are also incorrectly migrated. This is not on-topic for that site. Sep 1, 2011 at 8:37
  • 1
    @Marc, that FAQ explicitly states: Stack Overflow, Area 51 or the SE engine". I would put this under the first of those. If the question were a more general one related to how to do something similar to the way SO does it, then I would have let it go. But it asked explicitly about the methods in SO, which I contended it was clearly a meta question. I don't want to start an argument so I'll shut up now. Just explaining my reasoning.
    – user14860
    Sep 1, 2011 at 8:43
  • 3
    Given the "I want to know because I am also creating this type of website for my college project", one could interpret SO being mentioned for the sake of example.
    – CodeCaster
    Sep 1, 2011 at 8:48
  • paxdiablo, You are wrong, this is a SO question.
    – Laykes
    Sep 1, 2011 at 8:52

5 Answers 5

14

No "new page" is necessary. It is simply using the ASP.NET MVC route handling. For example, we handle the route "/questions/{postId}/{text}" and map that to a controller method such as:

public ActionResult AwesomePostHandlerMethod(int postId) {
    // lots of fun code here
}

Route-based (rather than page-based) handling is a core component of the MVC approach, and allows far more flexible (and friendly) urls than, say, /questions.aspx?id=12345 (the .aspx here is for illustration only; in reality we use razor (.cshtml) for the view).

2
1

That's called URL Rewriting.

3
  • 2
    I'm not sure it is, really. URL re-writing would mainly apply when re-mapping "friendly" URLs to the underlying paths. In the case of MVC there is no such underlying path. Sep 1, 2011 at 8:40
  • Well, since @Nikhil only mentions asp.net and not MVC, I assumed he'd simply like to add pretty URL's to an existing site, where rewriting comes in handy.
    – CodeCaster
    Sep 1, 2011 at 8:49
  • the question was edited; it was originally phrased "or any other method?" - but indeed, URL rewriting would count as an "other method" useful for different scenarios (with a similar aim). Sep 1, 2011 at 8:54
1

If you need that and not using Asp.Net MVC, you can look at System.Web.Routing, the same routing engine is available for classic Asp.Net apps.

0

It is something called Rewrite Engine. If you have an Apache server, check this link out.

1
  • 1
    I'm not sure it is, really. URL re-writing would mainly apply when re-mapping "friendly" URLs to the underlying paths. In the case of MVC there is no such underlying path. Sep 1, 2011 at 8:40
0

offtopic In a web site that uses same url scheme, the user was not redirected to the correct url, if the url was mistyped after the question id (or for example the title has changed - example of correct redirect at SO is How does Stack Overflow create its question URLs?). So the client called us and said:

When I rename a product, the old page is not deleted from the hard disk (see www.domain.com/1/test.html - I renamed it to test2, but both pages exists! In this way I'll run off of a disk space very quicly!

Lesson learned: after you fetch the page by it's ID, always make 301 redirect to the correct SE-friendly url if the current url do not match.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .