62,041
社区成员
发帖
与我相关
我的任务
分享
public interface IFormsAuthentication
{
void SignIn(string UserName, bool createPersistentCookie);
void SignOut();
}
public class FormsAuthenticationService : IFormsAuthentication
{
public void SignIn(string UserName, bool createPersistentCookie)
{
FormsAuthentication.SetAuthCookie(UserName, createPersistentCookie);
}
public void SignOut()
{
FormsAuthentication.SignOut();
}
}
public IFormsAuthentication FormsAuthen = new FormsAuthenticationService();
[AcceptVerbs(HttpVerbs.Post), ActionName("LoginSystem")]
public ActionResult LoginSystem(string UserName, string PassWord)
{
if (验证用户名密码方法,返回bool)
{
FormsAuthen.SignIn(存入Session的名字,false);
return this.RedirectToAction("ActionName", "Controller");
}
else
{
ViewData["LoginError"] = "用户名或密码不正确";
return View(登录页面);
}
}
public ActionResult LogOut()
{
FormsAuthen.SignOut();
return this.RedirectToAction("ActionName", "Controller");
}
Request.IsAuthenticated