Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do .NET sites hide .aspx extension of their files?

Tags:

asp.net

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?

like image 245
z-boss Avatar asked Oct 21 '08 22:10

z-boss


People also ask

How do I view ASPX files on my website?

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.

What does .aspx mean in a URL?

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.

How do ASPX files work?

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.


6 Answers

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.

like image 86
nlinus Avatar answered Sep 30 '22 01:09

nlinus


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.

like image 35
Craig Avatar answered Sep 30 '22 01:09

Craig


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

like image 45
Eoin Campbell Avatar answered Sep 30 '22 01:09

Eoin Campbell


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>
like image 25
Musakkhir Sayyed Avatar answered Sep 30 '22 03:09

Musakkhir Sayyed


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

like image 41
Chris Canal Avatar answered Sep 30 '22 02:09

Chris Canal


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.

like image 37
vfilby Avatar answered Sep 30 '22 03:09

vfilby