【发布时间】:2015-08-02 00:54:57
【问题描述】:
我很难理解如何向我的应用程序添加某种授权。这就是我的登录控制器现在的样子:
private UserProvider mUserProvider;
// GET: Login
public ActionResult Index()
{
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel model)
{
string userName = AuthenticateUser(model.UserName, model.Password);
if (!(String.IsNullOrEmpty(userName)))
{
Session["UserName"] = userName;
return View("~/Views/Home/Default.cshtml");
}
else
{
ModelState.AddModelError("", "Bad login");
return View("~/Views/Home/Login.cshtml");
}
}
public string AuthenticateUser(string username, string password)
{
//do stuff and get the special username
return sUsername;
}
我需要添加什么以确保未经身份验证的用户无法查看除了登录名之外的任何其他页面?
ps:我必须 100% 使用 AuthenticateUser。
感谢您的宝贵时间。
【问题讨论】:
-
你试过用
[Authorize]装饰你的其他安全操作方法吗? -
[Authorize]在控制器上。
标签: c# asp.net asp.net-mvc