Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900