Redirect to a Page Based on Logged In User
Updated March 30, 2010
Iron Speed Designer V7.0 and later
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 a menu item in a classic-style menu, you might redirect to a page showing data only for the logged in user.
Step 1: In the Application Explorer, select Presentation Layer, Menu Panels, Menu.ascx to display the menu control (classic menu style).
Step 2: Select the menu item you wish to modify and set these properties via the Property Sheet.
Group |
Property |
Setting |
[Application Generation] |
Button actions |
Custom |
[Application Generation] |
Button actions |
Redirect and Send Email Actions Stay on the current page |
Step 3: 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 4: Add the code customization below to Menu.ascx.cs, located in:
<Application Folder>\Menu Panels\Menu.ascx.cs
The simple code customization below assumes you are customizing 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.SecurityControls. GetCurrentUserID() == "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.SecurityControls. GetCurrentUserID() = "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.
You can customize this example so the user is redirected only when clicking on Menu2MenuItem on the ShowOrdersTable.aspx page. Instead of placing the code customization in Menu.ascx.cs, place it directly in the PreRender event of the ShowOrdersTable class.
Add your code customization to ShowOrdersTable.aspx.cs, located in:
<Application Folder>\<Table Name>\ShowOrdersTable.aspx.cs
C#:
public ShowOrdersTable()
{
this.PreRender += new EventHandler(Page_PreRender);
}
private void Page_PreRender(object sender, EventArgs e)
{
if(this.SecurityControls. GetCurrentUserID() == "ALFKI")
{
this.Menu.Menu2MenuItem.Button.RedirectUrl="http://www.ironspeed.com";
this.Menu.Menu2MenuItemHilited.Button.RedirectUrl = "http://www.ironspeed.com";
}
else
{
this.Menu.Menu2MenuItem.Button.RedirectUrl = “http://www.google.com”;
this.Menu.Menu2MenuItemHilited.Button.RedirectUrl = "http://www.google.com";
}
}
Visual Basic .NET:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
If Me.SecurityControls. GetCurrentUserID() = "ALFKI" Then
Me.Menu.Menu2MenuItem.Button.RedirectUrl = “http://www.ironspeed.com”
Me.Menu.Menu2MenuItemHilited.Button.RedirectUrl = “http://www.ironspeed.com”
Else
Me.Menu.Menu2MenuItem.Button.RedirectUrl = “http://www.google.com”
Me.Menu.Menu2MenuItemHilited.Button.RedirectUrl = “http://www.google.com”
End If
End Sub
Please note that you should also set the RedirectUrl property for the highlighted version of the menu as shown in the code above.