Click here to Skip to main content
14,241,409 members
Rate this:
Please Sign up or sign in to vote.
See more:
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");
            }
            
        }

    }
}
Posted
Updated 28-Jul-15 23:21pm
v2
Comments
Afzaal Ahmad Zeeshan 29-Jul-15 5:28am
   
Because browser doesn't save passwords by default, for security measures.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100