📄 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 + -