Introduction: In
this article today I will explain how we can implement URL routing in asp.net website similar as done
in asp.net MVC application.
Description:
In the previous article I have explained Populate Dropdown List dynamically using Asp.net MVC Razor, Code First migration in asp.net MVC 4, Populate Cascading Dropdown List in Asp.net MVC4 using Json and Jquery and What is Asp.net MVC? Its advantages and disadvantges.
URL routing provide the SEO friendly and clean url for application. To implement the clean url functionality in asp.net application follow the given steps:
URL routing provide the SEO friendly and clean url for application. To implement the clean url functionality in asp.net application follow the given steps:
Step 1:
Go to Tools>>Library
Package Manager>>Package Manager Console and type the below given
command:
Install-Package
Microsoft.AspNet.FriendlyUrls
After its installation you get a successfully added message.
Now you see in your application RouteConfig.cs and Site.Mobile.Master page has
been added. See attached snapshot:
In VB:
You see the RouteConfig file in C#. To implement the routing
in VB application you have to add RouteConfig.vb file instead of RouteConfig.cs
and write the code:
Imports System.Web.Routing
Imports Microsoft.AspNet.FriendlyUrls
Public Shared Sub RegisterRoutes(routes As
RouteCollection)
Dim settings = New
FriendlyUrlSettings()
settings.AutoRedirectMode = RedirectMode.Permanent
routes.EnableFriendlyUrls(settings)
End Sub
Note: You can delete/exclude the Site.Mobile.Master
and ViewSwitcher.ascx files if you want.
Step 2:
Add a Global.asax file to application. Write the following code
to file:
using System.Web.Routing;
protected void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
In VB:
Imports System.Web.Routing
Sub Application_Start(ByVal
sender As Object,
ByVal e As
EventArgs)
RouteConfig.RegisterRoutes(RouteTable.Routes)
End Sub
Build the application, run and check the result.
No comments:
Post a Comment