How to remove the ReturnURL querystring from my Login page?
How to remove the ReturnURL querystring from my Login page?
I do not recommend doing this because it is a loss of important functionality (in this case, redirect the user to the page where it came from and it was not authorized), but I will demonstrate how to remove it.
In the Views/Account/Login.cshtml
file, the line that generates the form should be something like this:
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
Change to:
@using (Html.BeginForm("Login", "Account", null, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
//
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login()
{
// ViewBag.ReturnUrl = returnUrl;
return View();
}
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
// return RedirectToLocal(returnUrl);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}