sepehr.aliakbary
دوشنبه 27 مرداد 1393, 10:15 صبح
با سلام به دوستان
من یه صفحهی لاگین درست کردم که قراره اگر کاربر مورد نظر در دیتابیس وجود نداشت با ایجکس یک پیغام خطا بده و اگر کاربر وجود داشت بره به یک صفحهی دیگه. برای این کار چه کدی باید توی کنترلر بذارم ؟
در حال حاضر کنترلر من ای شکلیه :
Context db = new Context();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string txtName,string txtPassword)
{
var users=db.Users.Where(x=>x.UserName==txtName&&x.Password==txtPassword).ToList();
Thread.Sleep(3000);
if (users.Count() == 0)
{
return Content("Your Username Or Password is Incorrect !");
}
else
{
HttpCookieCollection cookies = Request.Cookies;
if (cookies["ad"] != null)
{
Response.Cookies.Remove("CookieLogin");
}
else { }
HttpCookie user = new HttpCookie("CookieLogin");
user.Values["admin"] = "true";
user.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(user);
//return Content("Your Username Or Password is Correct !");
}
من یه صفحهی لاگین درست کردم که قراره اگر کاربر مورد نظر در دیتابیس وجود نداشت با ایجکس یک پیغام خطا بده و اگر کاربر وجود داشت بره به یک صفحهی دیگه. برای این کار چه کدی باید توی کنترلر بذارم ؟
در حال حاضر کنترلر من ای شکلیه :
Context db = new Context();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string txtName,string txtPassword)
{
var users=db.Users.Where(x=>x.UserName==txtName&&x.Password==txtPassword).ToList();
Thread.Sleep(3000);
if (users.Count() == 0)
{
return Content("Your Username Or Password is Incorrect !");
}
else
{
HttpCookieCollection cookies = Request.Cookies;
if (cookies["ad"] != null)
{
Response.Cookies.Remove("CookieLogin");
}
else { }
HttpCookie user = new HttpCookie("CookieLogin");
user.Values["admin"] = "true";
user.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(user);
//return Content("Your Username Or Password is Correct !");
}