62,046
社区成员
发帖
与我相关
我的任务
分享
[Authorize(Roles="普通,室长,院长,管理")]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MyUser.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName + "#" + model.Password, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "提供的用户名或密码不正确。");
}
}
// 如果我们进行到这一步时某个地方出错,则重新显示表单
return View(model);
}