Thursday, December 22, 2011

URL Routing in Dot Net 4.0

Code on Global.asax File
void Application_Start(object sender, EventArgs e)
            // Code that runs on application startup
            SqlConnection con = new SqlConnection("Data Source=XAPRIO-PC;Initial Catalog=URLDB;Persist Security Info=True;User ID=sa;Password=123");
            string strCmd = "SELECT * FROM tblRoute";
            SqlDataAdapter da = new SqlDataAdapter(strCmd, con);
            DataTable dt = new DataTable();
            foreach (DataRow row in dt.Rows)
                RouteTable.Routes.MapPageRoute(row["PageRouteName"].ToString(), row["PageRouteURL"].ToString(), row["PagePhysicalPath"].ToString());

Create Table 

Run your application and enter url "Route/Home" for Default.aspx