?? accountcontroller.cs
字號:
/*****************************************************************************************************
*
* 作 者: 夏竹青
*
* 創建日期:2006-10-18
*
* 功能描述:表示層的控制器,驗證登陸等。
*
*
* 處理過程:首先調用member的SignIn方法獲取密碼,然后進行判斷。正確則進入之前的頁面或進入跳轉頁面
*
*
* 調用說明:登陸頁面的code-behind代碼調用。
*
*
*************************************************************************************************/
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using AbstractLayer;//引用抽象層
using BusinessLayer;//引用業務層
namespace Mvc.Model
{
/// <summary>
/// AccountController 的摘要說明。
/// </summary>
public class AccountController
{
private const string ACCOUNT_KEY = "ACCOUNT_KEY";
private const string URL_DEFAULT = "Default.aspx";
private const string URL_SIGNIN = "EditAccount.aspx";
private const string URL_MANAGE = "MemberList.aspx";
private const string URL_CHECK = "../EditNestedDataGrid/WebForm1.aspx";
// private const string URL_ACCOUNTCREATE = "MyAccount.aspx?action=create";
private const string URL_ACCOUNTSIGNIN = "Default.aspx?action=signIn";
// private const string URL_ACCOUNTUPDATE = "MyAccount.aspx?action=update";
public AccountController()
{
//
// TODO: 在此處添加構造函數邏輯
//
}
public bool ProcessLogin(string userId, string password)
{
//使用帳戶業務邏輯層來登錄
Member member = new Member();
DataSet daStPwd = member.SignIn(userId);
try
{
//登錄成功,在Session中存儲狀態并且跳轉
if (password == daStPwd.Tables[0].Rows[0].ItemArray[0].ToString().Trim())
{
HttpContext.Current.Session[ACCOUNT_KEY] = daStPwd;
//決定用戶跳轉到哪兒
//返回到登錄成功的提示頁面
if (FormsAuthentication.GetRedirectUrl(userId, false).EndsWith(URL_DEFAULT))
{
FormsAuthentication.SetAuthCookie(userId, false);
HttpContext.Current.Response.Redirect(URL_ACCOUNTSIGNIN, true);
}
else
{
//將客戶端重定向到上一個頁面
FormsAuthentication.SetAuthCookie(userId, false);
if(userId == "admin")//如果是管理員則跳到管理員頁面
{
HttpContext.Current.Response.Redirect(URL_MANAGE,true);
}
else if(userId == "test")//如果是管理員則跳到管理員頁面
{
HttpContext.Current.Response.Redirect(URL_CHECK,true);
}
else
{
HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(userId, false), true);
}
}
return true;
}
else
{
//登錄失敗,返回false
return false;
}
}
catch
{
//異常處理,用戶不存在的情況。
return false;
}
}
//退出系統的方法
//用戶退出系統則清空Session,以及他們的驗證將被重置
public void LogOut()
{
FormsAuthentication.SignOut();//清除驗證信息
HttpContext.Current.Session.Clear();//清除Session的內容
HttpContext.Current.Session.Abandon();//取消當前對話
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -