I'm pretty sure stackoverflow.com is created with ASP.NET, but no matter where I click I see no .aspx extension in the address bar. How it is done and is there a particular reason for this?
You can use Firefox, Chrome, Edge, or any browser. All you have to do is, right-click on the . aspx file, click on Open with, and select Chrome (your browser). If you can't find your desired browser, click on Choose another app and locate your specified browser from the Program file.
Active Server Pages (ASPX) is a file format used by web servers and generated using the Microsoft ASP.NET framework - an open-source development framework used by web developers to create dynamic web pages, often with the . NET and C# programming languages.
A file with . aspx extension is a webpage generated using Microsoft ASP.NET framework running on web servers. ASPX stands for Active Server Pages Extended and these pages are displayed in web browser at user end when the URL is accessed.
In the case of stackoverflow, they use ASP.NET MVC rather than ASP.NET web forms. With web forms, the url is pointing to a file on your disk, while MVC is pointing to a controller action. If you're using webforms, you'd want to use URL rewriting. Scott Guthrie has a good article on doing URL rewriting.
This site uses the ASP.NET MVC framework and Urls map to routes not physical pages. The route passes on to the controller who then decides how to display the page.
Most likely its done by URL Rewriting...
The webserver is taking URLs like the ones in the address bar of your browser & repointing them to the ASPX pages behind the scenes
This can be done in a .NET HTTP Module or as an ISAPI Handler in IIS
Scott Gutherie has a good article on his site about URL Rewriting
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
you can achieve by modifying your web.config file.
<configuration>
<system.webserver>
<rewrite>
<rules>
<rule name="RemoveASPX" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
</rules>
</rewrite>
</system.webserver>
</configuration>
As other people have answered, StackOverflow is built using ASP.NET MVC and the ASP.NET MVC uses the System.Web.Routing. However System.Web.Routing is not part of ASP.NET MVC, it was RTMd with SP1, and means it's possible to use it without ASP.NET MVC. You can see how to use it with WebForms here: http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx and here: http://www.codeplex.com/ASPNET35Routing
You can do this and more with ISAPI rewrite (for IIS). It allows you to create friendly urls without all the ugly query strings. It gives users a friendlier interface and can make your content more searchable.
If you are using Apache, use mod_rewrite.
The basic premise of both is that they take a friendly url (like the one you see for this site), then they transform it using a series of rules (typically regexs that you specify) to internal urls or query strings that are easily understood by the code.
An example would be that they convert posts/edit/<postnumber>
to editPost.aspx?postNumber=<postnumber>
by using a transform rule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With