在您的登錄頁面,如果用戶成功登錄後,你可以存儲在Session和他們的角色你Home.aspx
只是有一點邏輯這決定了他們是否需要重新定向離開這個頁面或沒有,例如
login.aspx的
void LoginBtn_Click(Object sender, EventArgs e)
{
// have a function which returns the user object if successful, otherwise return null
User user = DoLogin(txtUsername.Text, txtPassword.Text);
if (user != null)
{
Session["UserRole"] = user.RoleName;
// if you aren't using the authentication stuff from the web.config then
// then you will need to manually redirect the user
}
}
home.aspx
void Page_Load(Object sender, EventArgs e)
{
string role = !String.IsNullOrEmpty(Session["UserRole"]) ? (string)Session["UserRole"] : String.Empty;
if (role == "ADMIN")
Response.Redirect("adminpanel.aspx");
}