How to install Microsoft.AspNet.FriendlyUrls


Learn more and find how to install the newly launched ASP.NET feature FriendlyUrls which allows you to create friendly URLs for your ASP.NET web applications without going through the hassles involved in Url rewriting.

Scott Hanselman's blog post about ASP.NET FriendlyUrls is an exciting news for all ASP.NET developers. Microsoft.AspNet.FriendlyUrls extension allows you to access your .ASPX pages without using the .ASPX extension. All you have to do is, install the new extension on your Visual Studio using Extension Manager and add a single line of code in to your Global.aspx file. Once the extension is references in your project and the code is added, you can access any of the .aspx pages in your website without using the .aspx file extension.

For example, if you have a webpage /resources/7360-How-install-Microsoft.AspNet.FriendlyUrls.aspx, you will be able to access it using the url /resources/7360-How-install-Microsoft.AspNet.FriendlyUrls

Isn't the url looking better and simpler without the file extension?

How to install and reference Microsoft.AspNet.FriendlyUrls extension


Right click on the "References" in the web application project. Select "Manage NuGet Packages".

Manage NuGet Packages

Now you can see the NuGet Package Manager. Click on "Online" on the left side to see the online packages. In the middle window, select "Include Prerelease" so that it will display all prerelease software also. (The Microsoft.AspNet.FriendlyUrls package is current on Alpha release and so you need to choose this option to see it in the list).

NuGet Manager

You may see a lot of packages in the list. If you are unable to find the Microsoft.AspNet.FriendlyUrls package in the list, you may search for it. Look for the search window on the top right corner. Type "AspNet.FriendlyUrls" and press Enter. It will show the package Microsoft.AspNet.FriendlyUrls. Click on the "Install" button to install this extension for your Visual Studio.

Install NuGet

In the next step, you will be asked to accept the license terms. Click on the "I Accept" to accept the license terms and proceed with the installation of the extension.

Install Package

The installation will complete within few seconds. One thing to be noted that you will not get any confirmation dialog that says installation is completed. All you will see that the install button will disappear from the NuGet Manager and you will see a small green color check mark that indicates the installation is complete.

NuGet installation

After the installation of the Microsoft.AspNet.FriendlyUrls extension, you will see a new file automatically added to your Visual Studio project with the name "packages.config". This file will have the following content:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.FriendlyUrls" version="1.0.0-alpha1" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
</packages>


You are almost done. Now, the only work remaining for you is to add a single line of code to your Global.asax file to use the newly installed extension. Open your Global.asax file. Add "RouteConfig.RegisterRoutes(RouteTable.Routes);" in the Application_Startup event as shown below:

void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}


Add a reference at the top of the Global.asax file as shown below:

using System.Web.Routing;


You are all set. Now you can access your web pages without using the .aspx file extension. All requests to the urls without the .aspx extension will be redirected to the corresponding .aspx pages.

Folder name conflict

If the file name without the .aspx extension matches a folder name under the same parent folder, you will have a conflict. The prerelease version of this extension prefers the folder name in such a case on my development computer, which runs Windows 7 and Visual Studio 2010.


Article by Tony John
Tony John is a professional blogger from India, who started his first Weblog in 1998 at Tripod.com. Tony switched to blogging as a passion blended business in the year 2000 and currently operates several popular web properties including IndiaStudyChannel.com, Techulator.com, dotnetspider.com and many more.

Follow Tony John or read 677 articles authored by Tony John

Comments

Guest Author: Carlos Loria25 Feb 2014

/resources/7360-How-install-Microsoft-AspNet-FriendlyUrls.aspx

It appears to me this is resolved by some.aspx?id=7630

but really don't know how.

Thanks...



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: