Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @if (Request.IsAuthenticated)
- {
- <li> @Html.ActionLink("Log Out", "LogOff", "User") </li>
- <li style="color:crimson">@Context.User.Identity.Name</li>
- }
- else
- {
- <li>@Html.ActionLink("Log On", "LogOn", "User")</li>
- <li>@Html.ActionLink("Register", "Register", "User")</li>}
- <authentication mode="Forms">
- <forms loginUrl="~/User/LogOn" defaultUrl="~/Book/Index"/>
- </authentication>
- [HttpPost]
- public ActionResult LogOn(LogOnModel model)
- {
- if (ModelState.IsValid)
- {
- if (Isvalid(model.Email, model.Pass)) {
- // FormsAuthentication.RedirectFromLoginPage(model.Email, false);
- FormsAuthentication.SetAuthCookie(model.Email, false);
- // Session["mail"] = model.Email;
- return RedirectToAction("Index", "Book");
- }
- else
- {
- ModelState.AddModelError("", "The user name or password provided is incorrect.");
- }
- }
- return View(model);
- }
- private bool Isvalid(string email, string password)
- {
- bool Isvalid = false;
- using (var db = new OperationDataContext())
- {
- var user = db.Users.FirstOrDefault(u => u.Email == email); //consultar el primer registro con los el email del usuario
- if (user != null)
- {
- if (user.Pass == password) //Verificar password del usuario
- {
- Isvalid = true;
- }
- }
- }
- return Isvalid;
- }
- <authentication>
- <anonymousAuthentication enabled="true" userName="" />
- <basicAuthentication enabled="false" />
- <clientCertificateMappingAuthentication enabled="false" />
- <digestAuthentication enabled="false" />
- <iisClientCertificateMappingAuthentication enabled="false">
- </iisClientCertificateMappingAuthentication>
- <windowsAuthentication enabled="false">
- <providers>
- <add value="Negotiate" />
- <add value="NTLM" />
- </providers>
- </windowsAuthentication>
- </authentication>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement