ASP.NET4 - Working with URL Routing



URL Routing - SEO Feature in ASP.NET4

//Include in Global.asax
using System.Web.Routing;
void RegisterRoutes(RouteCollection routes)
        {
            routes.MapPageRoute("list-show", "List/{type}", "~/List.aspx");
        }

Code to be included in Application_Start

  void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            RegisterRoutes(RouteTable.Routes);
        }

Code to be added in default.aspx

  List / People
         List / Books
          List / General

Get the listtype from RouteData

//code to be written in List.aspx.cs
protected void Page_Load(object sender, EventArgs e)
        {
            string listtype = Page.RouteData.Values["type"] as string;
            Label1.Text = listtype;
        }

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.