I want to create a similar type of url as stack overflow does when a question is created.
Example:
Non-ajax GET/POST using jQuery (plugin?)non-ajax-get-post-using-jquery-plugin
I am particularly interested in the last part which I have highlighed in bold. How do you achieve the affect of adding the title of the page to the url with the delimiter?
What is this technique called?
This technique called 'URL Rewriting'. You tagged question with 'asp.net' so MSDN may help you about that: http://msdn.microsoft.com/en-us/library/ms972974.aspx
The URL Rewriting for SO is provided by the Routing engine in ASP.NET MVC.
Stackoverflow is programmed in ASP.Net MVC and URL routing is a standard part of the package in MVC. Apart from URL routing it also offers many more advantages. So if you're building a new website, and want to get the benefit of URL Routing among other advantages, try making it in MVC.
Be warned though, you will have to learn quite a bit.
Like others have said the technique is called routing. Basically it takes your pretty formatted URL and maps it to some controller action. And according to Jon Galloway's answer IIS 7 has this functionality integrated. For previous versions of IIS you'll probably have to setup a wildcard application mapping to ASP.NET runtime and possibly add in your own HttpModule to your application's request pipeline to handle routing if your web framework of choice doesn't provide a routing facility.
You can accomplish this by lower casing the title and replacing non-alphanumeric characters with hyphens. Sometimes this bit is called a slug. You probably want to keep the slug length down as well so you don't run into URL length limit problems. You also have the option of generating the slug in a couple places:
Keep in mind slugs should not be used to look up page data, that's what a page ID is for; the slug should be optional. Your routing rules will just be concerned with getting the ID out of the URL and giving it to the correct controller action meanwhile ignoring everything after. In other words the only crucial part is the question ID. The slug is just sugar. :)
Don't forget that with this type of routing, people can link to your page with text you might have preferred them not to use.
I've seen this quite a lot with UK newspapers - they'll publish a story with a URL along the lines of
newspaperdoman.co.uk/articles/1128945/dog-bites-man
and then someone will link to it as
newspaperdoman.co.uk/articles/1128945/newspaper-in-crap-story-shocker
or whatever.
While routing is clearly the better option here, there are ways of faking it with minimal effort. For example, here's a simple way to get friendly URLs and some SEO:
Suppose you have the page:
Even without doing anything, the following URL will work:
You can also combine query data:
If you want, you can access that text using the request's
PathInfo
property.