{
//[Authorize]
/// <summary>
/// 授权通过跳转的视图,例如:帐号密码都为a、bb、ccc通过
/// </summary>
/// <returns></returns>
[Authorize(Users="a,bb,ccc")]
public ActionResult Welcome()
{
return View();
}
}
public class LogOnViewModel //用户实例类
{
/// <summary>
/// 用户名
/// </summary>
[DisplayName("用户名")]
public string UserName { get; set; }
/// <summary>
/// 密码
/// </summary>
[DisplayName("密码")]
public string Password { get; set; }
/// <summary>
/// 记住我
/// </summary>
[DisplayName("记住我")]
public bool RememberMe { get; set; }
}
//必须Web.config配置设置要跳转到的视图
//在system.web节点添加跳转到,授权显示的视图
//即 FormsAuthentication.SetAuthCookie(验证字段, bool是否授权通过);true跳转视图,false跳转失败页面
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
</system.web>