Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
BRH 48
#DOTNET 34
#ASP.NET 29
jQuery 22
ASP.NET 20
.NET 20
WPF 9
jquery interview questions 9
jquery faq 8
ASP.NET4 8

Archive · View All
February 2011 10
September 2011 4
August 2011 4
July 2011 4
May 2011 4
April 2011 4
March 2011 4
October 2011 4
June 2011 4
January 2011 4

Implementing Routing in ASP.NET 4 applications

Jul 10 2010 6:12AM by Hima   

How ASP.NET4 Routing Works?

Practical implementation of Routing in ASP.NET 4 is very simple. For example, consider the URL for my website that displays Label categories might look like below.

http://himabinduvejella.blogspot.com/labels.aspx?category=Microsoft

I do not want the URL to be traditional as mentioned above. I would like to see my URL as

http://himabinduvejella.blogspot.com/labels/Microsoft

Can this be done? The answer is Yes. But How?

  • System.Web.Routing is the new namespace that is responsible for handling ASP.NET Routing that comes along with .NET4 Framework.
  • This namespace contains classes to implement URL rewriting inside ASP.NET Web Forms. We can configure the application using new ASP.NET 4 Routing Engine to accept the dynamic URL and render the same information in the web.
  • ASP.NET 4.0 URL Routing, helps URLs to be mapped to ASP.NET MVC Controller classes and ASP.NET Web Forms based pages.
A Practical approach

Open VS2010 IDE and Create an ASP.Net Web application. Navigate to global.asax File. In 3 simple steps I will try to implement it.

Step1.

Import the Routing namespace in global.asax . This name space is responsible for all Routing classes.

using System.Web.Routing; 

Step2.

Define Routing in Global.asax, I have created a method called “RegisterRouteToAppHandler” as shown below.

void RegisterRouteToAppHandler(RouteCollection rc) 
{ 
rc.MapPageRoute ("Category", //Routname 
"Category/{Type}", //URL with parameter
"~/Category.aspx"); //Web Form to handle
}
  • The RouteCollection is new collection object that comes with Routing namespace; it provides a collection of Routes for ASP.NET Routing.
  • The MapPageRoute method provides a way to define routes for webform applications. This takes parameters as RouteName, URL with parameter (URL pattern of the route) and the Physical URL of the file.

Step3.

Now Call the above method in application_start. Note that the category.aspx resides on application’s route directory.

void Application_Start(object sender, EventArgs e)
{ 
// Code that runs on application startup 
RegisterRouteToAppHandler(RouteTable.Routes);
} 
The Route Table contains all the URL Routes for the entire web application. We can add any number of routes (that depends on the requirement) in event handler. The Following sample shows how can we use this routing in ASP.NET . Navigate to default.aspx . I have placed 3 link buttons and mentioned the postbackurl that is to be routed.
  
<p><asp:linkbutton runat="server" postbackurl="~/Category/MainCategory">
Main Category</asp:linkbutton></p>
<p><asp:linkbutton runat="server" postbackurl="~/Category/SEO">
SEO</asp:linkbutton> </p>
<p><asp:linkbutton runat="server" postbackurl="~/Category/ASP.NET">
ASP.NET</asp:linkbutton> </p>
<p><asp:linkbutton runat="server" postbackurl="~/Category/CS.NET">
C#.NET</asp:linkbutton> </p>
To Call RouteData Values

Create a web page called Category.aspx. Here is the code how we can access the RouteData Values in the code behind.

protected void Page_Load(object sender, EventArgs e)
{
string strType= Page.RouteData.Values["Type"] as string; 
Response.Write(strType);
} 

Now compile and run the application. This way we can play around with routing in ASP.NET

Routing using DataAccess

Accessing with Database ASP.NET 4 comes with new control that can be used with any ASP.NET Data Source control to bind a value from a route. Consider this example that shows how can be used to bind the select statement’s @categoryID parameter from the /category/{type} parameter in the URL route.

<asp:sqldatasource id="SqlDataSource" runat="server" 
connectionstring="<%$ ConnectionStrings:ConStr%>" 
selectcommand="select Categoryname, CategoryID from categories where categoryID =@categoryID
"><selectparameters><asp:routeparameter name="Type" routekey="
Type" /></selectparameters></asp:sqldatasource>

Tags: BRH, #DOTNET, URL Routing, Hima Vejella, ASP.NET4, SEO, SEO Feature, ASP.NET4 Routing, DOTNET, #ASP.NET, ASP.NET,


Hima
31 · 6% · 1776
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • Hima I had done this before, but I got one issue, that was, If I am using

    void RegisterRouteToAppHandler(RouteCollection rc) { rc.MapPageRoute ("Category", //Routname "Category/{TypeId}/{Type}", //URL with parameter "~/Category.aspx"); //Web Form to handle }

    then all the links in page being something like Category/12/Default.aspx instead of Default.aspx, so I have resolve this using <%=ResouleUrl("~/Default.aspx")%> but sometimes this also create problem, so can you please write something on this??

    I hope you will be come up with good solution. I will waiting for your opinion and article on this topic. Thanking you.

    commented on Jun 29 2011 12:24PM
    Haresh Ambaliya
    120 · 1% · 428

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]