ASP.NET MVC Form身份验证

web.confing中加入

<authentication mode="Forms"><forms loginUrl="~/Home/index" timeout="2880"/></authentication>

通过验过验证

C# code

if (new account.Data.Bll().Login(username, possWord))

//验证身份 {

FormsAuthentication.SetAuthCookie(username, false);

//验证通过return RedirectToAction("index", "bc");

}

受控制验证页

在上面加入[Authorize]

C# code

[Authorize]

///<summary>/// 显示所有账户信息 ///</summary>///<returns>账户信息列表</returns>

public ActionResult Index()