Redirect to a Page Based on Logged In User

It is often useful to dynamically redirect a user to a particular page based on the logged in user ID or logged in user role.
- Pooja Daga, Technical Support Engineer, Iron Speed, Inc.

March 29, 2006
Iron Speed Designer V3.2

Introduction
It is often useful to dynamically redirect a user to a particular page based on the logged in user ID or logged in user role. For example, when a user clicks on a menu item, you might redirect to a page showing data only for the logged in user. The steps are listed below.
Procedure
Step 1: In the Application Explorer, select Presentation Layer, Menu Panels, Menu.ascx. This displays the menu control in the Design tab. Double-click on the menu item you wish to modify to display the Page Properties dialog. Select the Bindings tab.

Step 2: Select the "Send custom command" option, enter a command name, and select "Page (Advanced)". When the menu item is clicked, this custom command will be executed.

Step 3: Select the "Stay on the current page" option.

Step 4: Add the code customization below to the Menu.ascx.cs file, located in:

...\<Application Folder>\Menu Panels\Menu.ascx.cs

The simple code customization below assumes you are extending the Menu2MenuItem control. Modify the code customization to suit your needs.

C#:

public Menu()
{
      this.Init += new System.EventHandler(myInit);
}
private void myInit(object sender,System.EventArgs e)
{
      this.Menu2MenuItem.Button.Click+= new System.EventHandler(Onmenu2MenuItem_Click);
}

private void Onmenu2MenuItem_Click(object sender,System.EventArgs e)
{
   if(this.SystemUtils.GetLoginId()=="ALFKI")
   {
      this.Page.Response.Redirect("http://www.ironspeed.com");
   }
    else
   {
      this.Page.Response.Redirect("http://www.gmail.com");
   }
}

Visual Basic .NET:

Private Sub Page_init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
   AddHandler Menu2MenuItem.Button.Click, AddressOf Menu2MenuItem_click
End Sub

Private Sub menu2menuitem_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
   If (Me.SystemUtils.GetUserID = "ALFKI") Then
      Me.Page.Response.Redirect("Http://www.ironspeed.com")
   Else
      Me.Page.Response.Redirect("Http://www.hotmail.com")
   End If
End Sub

Step 5: Build and run your application.

About the Author
Pooja Daga
Technical Support Engineer, Iron Speed, Inc.

Pooja has experience developing Web applications using .NET technology. She started her career with PCS, a leading software services company headquartered in India and has been with Iron Speed since 2005.

Pooja holds an M.S. degree in Computer Application and a B.S. degree in Electrical engineering from Maharaja Sayajirao University in India.



  Privacy Statement