using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MVCRegistration.Controllers { public class HomeController : Controller { [AllowAnonymous] public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View(); } public ActionResult About() { ViewBag.Message = "Your app description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } public ActionResult Login() { return View(); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Login(User u) { if(ModelState.IsValid) { using (MyDatabaseEntities dc=new MyDatabaseEntities()) { var v=dc.Users.Where(a=>a.UserName.Equals(u.UserName) && a.Password.Equals(u.Password)).FirstOrDefault(); if(v !=null) { Session["LogedUserId"] = v.UserId.ToString(); Session["LogedUserFullName"] = v.FullName.ToString(); return RedirectToAction("AfterLogin"); } } } return View(u); } public ActionResult AfterLogin() { if(Session["LogedUserId"]!=null) { return View(); } else { return RedirectToAction("Index"); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)