OK I'v researched and tried every single suggestion (individually of course) before posting this and I hit a wall every time
This is my log in view I used ViewBag to pass the ReturnUrl value as I've seen in many answers to this problem
<h2>Login</h2>
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { role = "form" }))
{
@Html.AntiForgeryToken()
...............
And this is the login action result
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(UserLogin login, string returnUrl="")
{
string message = "";
using (NerdsContext nc = new NerdsContext())
{
var v = nc.User.Where(a => a.email == login.email).FirstOrDefault();
if (v != null)
{
if (!v.IsEmailVerified)
{
ViewBag.Message = "Please verify your email first";
return View();
}
if (string.Compare(Crypto.Hash(login.password), v.password) == 0)
{
int timeout = login.rememberMe ? 525600 : 20;
var ticket = new FormsAuthenticationTicket(login.email, login.rememberMe, timeout);
string encrypted = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
cookie.Expires = DateTime.Now.AddMinutes(timeout);
cookie.HttpOnly = true;
Response.Cookies.Add(cookie);
if (Url.IsLocalUrl(returnUrl))
{
ViewBag.ReturnUrl = returnUrl;
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Nerd", "Home");
}
}
else
{
message = "Invalid credential provided";
}
}
else
{
message = "Invalid credential provided";
}
}
ViewBag.Message = message;
return View();
}
And finally this is the lines I added in web.config file
<authentication mode="Forms">
<forms cookieless="UseCookies" loginUrl="/Account/Login" timeout="30" slidingExpiration="true" protection="All"></forms>
</authentication>
And when I run this I never get to actually login it always send me back to the login page and the value of the returnUrl is always null
So what is going on here????
What I have tried:
I've seen lots of posts about this issue and tried almost all of them but with no use..I'd appreciate any help here