Step 1: Enable role-based security using the Role-Based Security Wizard in Iron Speed Designer.
Step 2: Create an application with the Orders table in the Northwind database. Set the start page
as ShowOrdersTablePage.aspx. Set the access permissions for ShowOrdersTablePage.aspx to “Grant access only
to signed in users”.
Step 3: Add the following code in the SignIn_Control class of SignIn_Control.ascx.cs located in:
|
...\<Application Folder>\Shared\SignIn_Control.ascx.cs
|
C#:
public SignIn_Control()
{
this.LoginSucceeded+= new LoginSucceededHandler(SignIn_Control_LoginSucceeded);
}
private void SignIn_Control_LoginSucceeded(object sender, System.EventArgs e)
{
string myId = this.SystemUtils.GetUserID();
string whereStr = "EmployeeID='" + myId +"'";
EmployeesRecord myrec = EmployeesTable.GetRecord(whereStr);
if(myrec != null)
{
System.Web.HttpContext.Current.Session["mySessionVar"] = myrec.DeptID;
}
}
|
Visual Basic .NET, .NET Framework 1.1:
Private Sub Page_LoginSucceeded(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.LoginSucceeded
Dim myId As String = Me.SystemUtils.GetUserID
Dim whereStr As String = "EmployeeID='" & myId & "'"
Dim myrec As EmployeesRecord = EmployeesTable.GetRecord(whereStr)
If (Not myrec Is Nothing) Then
System.Web.HttpContext.Current.Session("mySessionVar") = myrec.DeptID
End If
End Sub
|
Visual Basic .NET, .NET Framework 2.0
Private Sub Page_LoginSucceeded(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.LoginSucceeded
Dim myId As String = Me.SystemUtils.GetUserID
Dim whereStr As String = "EmployeeID='" & myId & "'"
Dim myrec As EmployeesRecord = EmployeesTable.GetRecord(whereStr)
If (Not myrec Is Nothing) Then
System.Web.HttpContext.Current.Session("mySessionVar") = myrec.DeptID
End If
End Sub
|
Note: DeptID is a field (of type int ) added to the Employees table (Northwind) in the database.
You can replace DeptID with any other field.
Step 3:
For .NET Framework 1.1, add the following code in the BaseApplicationPage class of BaseApplicationPage.cs
located in:
|
...\<Application Folder>\Shared\BaseApplicationPage.cs
|
For .NET Framework 2.0, add the code in the BaseApplicationPage class of BaseApplicationPage.cs located
in:
|
...\<Application Folder>\App_Code\Shared\BaseApplicationPage.cs
|
C#, .NET Framework 1.1:
Public BaseApplicationPage()
{
this.Load+= new System.EventHandler(BaseApplicationPage_Load);
}
private void BaseApplicationPage_Load(object sender, System.EventArgs e)
{
if(System.Web.HttpContext.Current.Session["MySessionVar"]!= null)
{
int myDeptID = (int)System.Web.HttpContext.Current.Session["MySessionVar"];
if(myDeptID ==1)
{
if(this.Page.GetType().Name == "EditOrdersPage_aspx" || this.Page.
GetType().Name=="AddOrdersPage_aspx")
{
this.Page.Response.Redirect("../Orders/ShowOrdersTablePage.aspx");
}
}
}
}
|
C#, .NET Framework 2.0:
public BaseApplicationPage()
{
base.Load += new System.EventHandler(this.Page_Load);
this.Load += new System.EventHandler(BaseApplicationPage_Load);
}
private void BaseApplicationPage_Load(object sender, System.EventArgs e)
{
if (System.Web.HttpContext.Current.Session["MySessionVar"] != null)
{
int myDeptID = (int)System.Web.HttpContext.Current.Session["MySessionVar"];
if (myDeptID == 1)
{
if (this.Page.GetType().Name == "orders_editorderspage_aspx" ||
this.Page.GetType().Name == "orders_addorderspage_aspx")
{
this.Page.Response.Redirect("../Orders/ShowOrdersTablePage.aspx");
}
}
}
}
|
Visual Basic .NET, .NET Framework 1.1:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Not System.Web.HttpContext.Current.Session("MySessionVar") Is Nothing) Then
Dim myDeptID As Integer = CType(System.Web.HttpContext.Current.Session
("MySessionVar"), Integer)
If (myDeptID = 1) Then
If (TypeOf (Page) Is EditOrdersPage OrElse TypeOf (Page) Is AddOrdersPage) Then
Me.Page.Response.Redirect("../Orders/ShowOrdersTablePage.aspx")
End If
End If
End If
End Sub
|
Visual Basic .NET, .NET Framework 2.0:
Private Sub myPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Not System.Web.HttpContext.Current.Session("MySessionVar") Is Nothing) Then
Dim myDeptID As Integer = CType(System.Web.HttpContext.Current.Session
("MySessionVar"), Integer)
If (myDeptID = 1) Then
If (Me.Page.GetType.Name = "orders_editorderspage_aspx" OrElse
Me.Page.GetType.Name = "orders_addorderspage_aspx") Then
Me.Page.Response.Redirect("../Orders/ShowOrdersTablePage.aspx")
End If
End If
End If
End Sub
|
|