Cheap ASP.NET 4.5 Hosting :: Increase SEO Rank for Your ASP.NET Site with SEO Friendly URLs

Increase SEO Rank for Your ASP.NET Site with SEO Friendly URLs

To increase your site SEO rank, you should make SEO friendly URLs. In ASP.NET Web Forms applications, a URL is tied to a physical .aspx file. This default mapping between a URL and physical file makes it difficult for Web Forms applications to generate SEO friendly URLs. One option available to ASP.NET developers is to use URL routing features. Alternatively they can also use Friendly URLs – a feature that allows you to quickly and easily use SEO friendly URLs in Web Forms applications. This article discusses how.


For example, this URLs http://www.somewebsite/WebForm1/2014/03/10/1234 is more friendly URLs than this one http://somewebsite/WebForm1.aspx?postid=1

Installing Friendly Url via NuGet

In order to use ASP.NET FriendlyUrls you need to install the required assemblies using a NuGet package. So, open Visual Studio 2012 and create a blank ASP.NET Web Forms application. Then click on the Project > Manage NuGet Packages menu option. In the resulting dialog search for FriendlyUrls, you should see the Microsoft ASP.NET Friendly URLs entry listed as shown in the following figure.

Microsoft ASP.NET Friendly URLs

Once you install the necessary NuGet package you will find that a reference is added to the Microsoft.AspNet.FriendlyUrls assembly. Now you are ready to use FriendlyUrls in your application.

Enabling Friendly Urls

Next, open Global.asax file in Visual Studio and write the following code in its Application_Start event handler.

The above code calls the EnableFriendlyUrls() method on the Routes collection. Calling the EnableFriendlyUrls() method enables FriendlyUrls for your application and you can use all the Web Form URLs without the .aspx extension. For example, instead of accessing a web form as /samplewebsite/WebForm1.aspx you can simply say /samplewebsite/WebForm1

Remember that EnableFriendlyUrls() is an extension method and you must import the following namespaces at the top of Global.asax.

Getting Information about FriendlyUrls

Inside the Web Form you may want to know the path information about a FriendlyUrl. You can easily obtain that information as shown below:

As you can see from the above code, several extension methods get added to the Request object. The GetFriendlyUrlFileVirtualPath() method returns the virtual path corresponding to the FriendlyUrl being accessed. For example, for a friendly URL http://somewebsite/WebForm1 it will return ~/WebForm1.aspx

The GetFriendlyUrlFileExtension() method returns the physical file extension of a FriendlyUrl. For web form files, it will be .aspx.

You can also generate FriendlyUrls via code using the Resolve() method of the FriendlyUrl class. The Resolve() method accepts a virtual path and resolves that path to the corresponding FriendlyUrl.

The Href() method of the FriendlyUrl class can be used to generate hyperlink URLs. It accepts the virtual path of the FriendlyUrl followed by URL segments (more on that later). For example, if you wish to generate a hyperlink that points to /somewebsite/WebForm1/2014/03/10/1234 then the first parameter will be ~/WebForm1 and URL segments will be 2014, 03,10 and 1234.

Accessing URL Segments in Code

FriendlyUrls features are not limited to generating extensionless URLs. You can also pass data to the underlying Web Form through URL segments. In the blog engine example we discussed earlier, the year, month and day of publication is passed to the Web Form along with the post ID. These pieces of information are passed as URL segments as shown below:


The URL segments that you pass along with a FriendlyUrl can be retrieved inside the Web Form code-behind file as shown below:

As you can see, the code-behind uses the GetFriendlyUrlSegments() extension method on the Request object. The GetFriendlyUrlSegments() returns an IList of string. Once retrieved you can access and parse the individual segment and assign to a class named BlogPost. The BlogPost class is a simple class with four public properties, viz. Year, Month, Day and PostId.

FriendlyUrls and ValueProviders

It is also easy to use FriendlyUrls with data bound controls such as GridView and FormView. Consider, for example, that the Web Form that displays a blog post houses a FormView control to do so. The FormView control can use SelectMethod and ItemType properties to specify a method returning the data to be bound and type of the data being returned respectively.

As you can, see the ItemType property points to the BlogPost class you created earlier and the SelectMethod property points to a public method named GetBlogPost(). The GetBlogPost() method is shown below:

As you can see the GetBlogPost() method has four parameters, viz. year, month, day and postid. These parameter values will be passed through the URL segments as discussed earlier. You need to map the URL segments with the appropriate method parameters. You can do this using the [FriendlyUrlSegments] attribute. The [FriendlyUrlSegments] attribute is a value provider and is applied to various parameters of the GetBlogPost() method. It takes an index of the URL segment you wish to bind with a method parameter. In the above example, if you have URL like this:


Then year, month, day and postid parameters will be 2014, 03,10 and 1234 respectively. Although the above example simply constructs a BlogPost object based on the URL segment values you can add any custom processing here.

Cheap ASP.NET 4.5 Hosting Recommendation

  1. Build Your Website
    Use‘s website building tools to get that special, customized look for your website. A nifty wizard will walk you through the process.
  2. All-inclusive Prices Unbeatable Value
    Other companies promise cheap hosting, but then charge extra for setup fees, higher renewal rates, or promotional services. With, the listed price is the number you’ll pay, and you can expect a fully loaded, comprehensive suite of web services.
  3. Fast and Secure Server
    Their powerful servers are especially optimized and ensure the best ASP.NET 4.5 performance. They have best data centers on three continent and unique account isolation for security.
  4. Easy to Use and Manage webspace explorer lets you manage your website files with a browser. A control panel lets you set up and control your server functions with ease.
[stextbox id=”asp_net_hosting” caption=” is Microsoft No #1 Recommended Windows Hosting Partner”] is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to for the ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, .NET 4.5.2/ASP.NET 4.5.1, ASP.NET MVC 6.0/5.2, Silverlight 5 and Visual Studio Lightswitch. Click here for more information[/stextbox]
Rate this post

Anjali Punjab

Anjali Punjab is a freelance writer, blogger, and ghostwriter who develops high-quality content for businesses. She is also a HubSpot Inbound Marketing Certified and Google Analytics Qualified Professional.