I am using SimpleMembership in my ASP.NET MVC 4 Project. After I login, I am unable to get the current UserName and the current UserId, here is my Login function:
[HttpPost]
public ActionResult Login(FormCollection form)
{
bool success = WebSecurity.Login(form["username"], form["password"], false);
if (success)
{
string returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl == null)
{
Response.Redirect("~/home/index?userId=" + WebSecurity.CurrentUserId + "&userName=" + WebSecurity.currentUserName);
}
else
{
Response.Redirect(returnUrl);
}
}
return View();
}
On this line Response.Redirect("~/home/index?userId=" + WebSecurity.CurrentUserId + "&userName=" + WebSecurity.currentUserName);
WebSecurity.CurrentUserId returns -1 and WebSecurity.currentUserName returns ""
Am I missing something? Any help would be much appreciated.
However in my View if I do this @{ int value; value = WebSecurity.currentUserID; } @{ ViewBag.Title = value; } the title in my browser is the correct currentUserId