Sunday 14 October 2012

What is url routing?


Hi Friend’s ,Here I have explained a new feature in asp.net 4.0.

Introduction:

URL routing is one of the new thing in Asp.net4.0.You can just said that you can reduce the url length and make it user friendly i.e you can arrange the url in your own way. Developers  build the url dynamism , readability and flexibility to the user. You have seen lot of url’s that are very lengthy and ugly. User’s avoid to cut and paste or to remember it. It is very tuff task for user ‘s that means it is not user friendly.
You have seen url’s like
We know how ugly they are. To avoid such type of url name ,Asp.net 4.0 brings a new concept called url routing.
With the use of url routing  ,you can manage your url in proper way so that it is easy for cut and paste or user can remember the url.
After Using of url routing the url will become as below
Procedure for url Routing:
First you create a simple web project in which at least two web form.
Add  Global.asax file in this project.
Open Global.asax file  and write the code in following section:-
<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
       
        System.Web.Routing.RouteTable.Routes.MapPageRoute("",
    "Home",
    "~/linq/Default.aspx"); // in this code ~/linq/Default.aspx is the original name(url) and Home is the new name (It is written by myself or you can give the name  whatever you want )

    }
  
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }
       
    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.

    }
      
</script>

 This is the simple url routing .
If you want to write the code on button event or any other event. For this you have to write the new name in Respose.Redirect(). Method.
For Example:
protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Home");
    }

Hope this will help u. If any query regarding this please Conatact me at sushilct86@gmail.com.
If you like this post do not forget to cooment.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.