ASP.NET URL Routing Web Forms Application

ASP.NET URL Routing Web Forms Application

Today, We want to share with you ASP.NET URL Routing Web Forms Application.
In this post we will show you Routing in ASP.NET MVC Web Forms Application, hear for mplement URL Routing in ASP.Net Web Forms we will give you demo and example for implement.
In this post, we will learn about Single Page Apps with ASP.NET Routing and Templating with an example.

Routing in ASP.NET Web Forms Application

This post shows how to make changes in an ASP.NET Web site to include ASP.NET routing features. At the end of this post, you will get an idea about how routing can be achieved in web application.

This post describes, how you can do the following with a minimum amount of code:

  • Define custom URL patterns that are independent of physical file names.
  • Generate URLs based on route URL parameter values by using markup or code.
  • In a routed page, retrieve values passed in URL segments by using markup or code.
READ :  Simple HTML Editor Example Made with vuejs - vue text editor

URL Routing is supported in.Net 3.5 SP1 or higher frameworks, if you want to use it in Visual Studio 2008 you will need to install.Net Framework 3.5 Service Pack 1.

Add Global.asax file to the Web Application

The very first thing you need to do is add a Global.asax file to the ASP.Net Website project. You can find this file inside Add New Item dialog in Visual Studio.

Example : ASP.NET Routing with Parameters

Add the following lines of lines code in the Global.asax

using System;
using System.Web.Routing;

namespace RoutingDemo
  public class Global : System.Web.HttpApplication
  protected void Application_Start(object sender, EventArgs e)

  private void RegisterRoutes(RouteCollection routes)
  routes.MapPageRoute("Student", "Student", "~/StudentDetails.aspx");
  routes.MapPageRoute("StudentDetails", "StudentDetails/{CustomerId}", "~/StudentDetails.aspx");

in the above source code, I have made use of MapPageRoute method which accepts the following three parameters.

READ :  Angular ng controller directive Example

1. routeName:

This parameter specify name of route. It must be unique for every route.In the example, I have used two routes namely ‘Student’ and ‘StudentDetails’.

2. routeUrl:

The Route URL you want to implement. Here in above example ‘StudentDetails.aspx’ page can be accessed by writing only ‘Student’,also ‘StudentDetails.aspx?id=1’ can be accessed by writing only ‘StudentDetails/1’.

3. physicalFile:

This parameter specify actual page where redirection is expected.

Benefits of Routing

1. More descriptive/meaningful URLs can be used, which is easy to understand by users and search engines.
2. It makes SEO frienly URL.
3. It makes Easy for URL rewrite rules.
4. The file extension can be hide by routing.

READ :  VueJS Installation and Configuration - VueJS Environment Setup

Read :

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Routing in ASP.Net Web Form Application.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Add a Comment

Your email address will not be published. Required fields are marked *