Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. [AllowAnonymous]
  2. [HttpPost]
  3. public ActionResult Login(LoginModel model, string returnUrl)
  4. {
  5. if (ModelState.IsValid)
  6. {
  7. if (System.Web.Security.Membership.ValidateUser(model.UserName, model.Password))
  8. {
  9. FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
  10. if (Url.IsLocalUrl(returnUrl))
  11. {
  12. return Redirect(returnUrl);
  13. }
  14. else
  15. {
  16. return RedirectToAction("Index", "Home");
  17. }
  18. }
  19. else
  20. {
  21. ModelState.AddModelError("", "The user name or password provided is incorrect.");
  22. }
  23. }
  24.  
  25. // If we got this far, something failed, redisplay form
  26. return View(model);
  27. }
  28.  
  29. <authentication mode="Forms">
  30. <forms loginUrl="~/Account/Login" timeout="3600" />
  31. </authentication>
  32.  
  33. <!--<modules>
  34. <remove name="FormsAuthentication" />
  35. </modules>-->
  36.  
  37. [AllowAnonymous]
  38. [HttpPost]
  39. public ActionResult Login(string userName, string password, string returnUrl)
  40. {
  41. if (ModelState.IsValid)
  42. {
  43. if (HttpContext.User.Identity.IsAuthenticated)
  44. {
  45. return View(returnUrl);
  46. }
  47. else
  48. {
  49. if (System.Web.Security.Membership.ValidateUser(userName, password))
  50. {
  51. FormsAuthentication.SetAuthCookie(userName, false);
  52. if (Url.IsLocalUrl(returnUrl))
  53. {
  54. return RedirectToAction("Login", new { userName = userName, password = password, returnUrl = returnUrl });
  55. //return Redirect(returnUrl);
  56. }
  57. else
  58. {
  59. return RedirectToAction("Index", "Home");
  60. }
  61. }
  62. }
  63. else
  64. {
  65. ModelState.AddModelError("", "The user name or password provided is incorrect.");
  66. }
  67. }
  68.  
  69. // If we got this far, something failed, redisplay form
  70. return View(model);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement