当我开始我的asp mvc4项目时。我不知道登录需要什么,但现在我知道FormsAuthentication和WebSecurity但我不能使用它因为空mvc,我必须当我开始项目时选择互联网应用程序! 如果可能,我想用一些东西给用户一个Session,他们可以在我的Controller中使用[Athourized] ActionResults。 这是我的登录号ActionResult和我评论的Autherize Anotation!
[HttpPost]
[AllowAnonymous]
public ActionResult Login(user users, String username, String password)
{
try
{
user lUser = db.users.Single(pUser => pUser.username ==
username && pUser.password == password);
if (lUser.username == username && lUser.password == password)
{
//Session["session"] = users;
return RedirectToAction("Index");
}
return View();
}
catch(Exception ex)
{
HttpNotFoundResult result = new HttpNotFoundResult("User Not Found!");
return result;
}
}
[HttpGet]
public ActionResult Login()
{
return View();
}
例如,我希望仅向管理员授予编辑权限!
//[Authorize(Users = "Admin")]
public ActionResult Edit(user users)
任何想法?