Advertisement
Guest User

Untitled

a guest
Jul 15th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. @if (Request.IsAuthenticated)
  2. {
  3.  
  4. <li> @Html.ActionLink("Log Out", "LogOff", "User") </li>
  5. <li style="color:crimson">@Context.User.Identity.Name</li>
  6. }
  7. else
  8. {
  9. <li>@Html.ActionLink("Log On", "LogOn", "User")</li>
  10. <li>@Html.ActionLink("Register", "Register", "User")</li>}
  11.  
  12. <authentication mode="Forms">
  13. <forms loginUrl="~/User/LogOn" defaultUrl="~/Book/Index"/>
  14. </authentication>
  15.  
  16. [HttpPost]
  17. public ActionResult LogOn(LogOnModel model)
  18. {
  19.  
  20. if (ModelState.IsValid)
  21. {
  22.  
  23. if (Isvalid(model.Email, model.Pass)) {
  24. // FormsAuthentication.RedirectFromLoginPage(model.Email, false);
  25. FormsAuthentication.SetAuthCookie(model.Email, false);
  26. // Session["mail"] = model.Email;
  27. return RedirectToAction("Index", "Book");
  28. }
  29. else
  30. {
  31. ModelState.AddModelError("", "The user name or password provided is incorrect.");
  32. }
  33.  
  34. }
  35.  
  36. return View(model);
  37. }
  38. private bool Isvalid(string email, string password)
  39. {
  40. bool Isvalid = false;
  41. using (var db = new OperationDataContext())
  42. {
  43. var user = db.Users.FirstOrDefault(u => u.Email == email); //consultar el primer registro con los el email del usuario
  44. if (user != null)
  45. {
  46. if (user.Pass == password) //Verificar password del usuario
  47. {
  48. Isvalid = true;
  49. }
  50. }
  51. }
  52. return Isvalid;
  53. }
  54.  
  55. <authentication>
  56.  
  57. <anonymousAuthentication enabled="true" userName="" />
  58.  
  59. <basicAuthentication enabled="false" />
  60.  
  61. <clientCertificateMappingAuthentication enabled="false" />
  62.  
  63. <digestAuthentication enabled="false" />
  64.  
  65. <iisClientCertificateMappingAuthentication enabled="false">
  66. </iisClientCertificateMappingAuthentication>
  67.  
  68. <windowsAuthentication enabled="false">
  69. <providers>
  70. <add value="Negotiate" />
  71. <add value="NTLM" />
  72. </providers>
  73. </windowsAuthentication>
  74.  
  75. </authentication>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement