I have searched many posts here regarding custom user authentication but none have addressed all of my concerns
I am new to ASP.NET MVC and have used traditional ASP.NET
1-Add This Code To WebConfig
2-To Action Use This code
[HttpPost]
public async Task Login(string UserName,string Password)
{
var q = await userpro.Login(UserName, Password);
if (q.Resalt)
{
//Add User To Cookie
Response.Cookies.Add(FormsAuthentication.GetAuthCookie(UserName, false));
return RedirectToAction("ShowUsers", "User");
}
else
{
ViewBag.Message = q.Message;
return View();
}
}
3-You Should Add This Attribute To Your Action [Authorize]
4-To This Code You Can Get UserName In Cookie
public async Task ShowUsers(int Page = 0)
{
string UserName= User.Identity.Name;
return View(await user.GetAllUser(Page));
}