خیر من از identity استفاده نمیکنم.
از ممبرشیپ ستفاده کردم.
یه جدول یوزر دارم که کاربران رو توش ذخیره میکنم.
درکنترلر home هم یه اکشن login ویه اکشن register
اکشن لاگین بصورت زیر هست:
[HttpPost]
public ActionResult Login(string username, string password, bool rememberme)
{
var blUser = new UserRepository();
if (blUser.Exist(username, password))
{
FormsAuthentication.SetAuthCookie(username, rememberme);
return RedirectToAction("Index");
}
else
{
ViewBag.Message = "نام کاربری یا پسورد اشتباه است";
}
return View();
}
که authentication رو در گلوبال انجام دادم:
protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
{
if (FormsAuthentication.CookiesSupported == true)
{
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
var blUser = new UserRepository();
string roles = blUser.Where(p => p.Email == username).Single().Roles;
e.User = new GenericPrincipal(new System.Security.Principal.GenericIdentity(username ), roles.Split(','));
}
}
بدرستی کد شما رو متوجه نشدم الان من باید زمانیکه یه یوزر ثبتنام میکنه رو بصورت اتوماتیک لاگین رو براش انجام بدم؟