Hi mayankv83,
Check this example. Now please take its reference and correct your code.
HTML
Login
<asp:TextBox runat="server" ID="txtUserName" />
<asp:Button Text="Login" runat="server" OnClick="OnLogin" />
Home
User Name: <asp:Label ID="lblUser" runat="server" />
Code
Namespaces
C#
using System.Web.Routing;
VB.Net
Imports System.Web.Routing
Global.asax
C#
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Home", "{user}/home", "~/Home.aspx");
}
}
VB.Net
Public Class Global_asax
Inherits HttpApplication
Sub Application_Start(sender As Object, e As EventArgs)
RegisterRoutes(RouteTable.Routes)
End Sub
Private Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.MapPageRoute("Home", "{user}/home", "~/Home.aspx")
End Sub
End Class
Login
C#
protected void OnLogin(object sender, EventArgs e)
{
// Code to validate login.
Session["User"] = txtUserName.Text.Trim();
Response.Redirect(string.Format("{0}/home", Session["User"].ToString()));
}
VB.Net
Protected Sub OnLogin(ByVal sender As Object, ByVal e As EventArgs)
Session("User") = txtUserName.Text.Trim()
Response.Redirect(String.Format("{0}/home", Session("User").ToString()))
End Sub
Home
C#
protected void Page_Load(object sender, EventArgs e)
{
// Validate user is login or not.
if (Session["User"] != null)
{
lblUser.Text = Page.RouteData.Values["user"].ToString();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Session("User") IsNot Nothing Then
lblUser.Text = Page.RouteData.Values("user").ToString()
End If
End Sub
Screenshot