How to remove the ReturnUrl querystring?

1

How to remove the ReturnURL querystring from my Login page?

    
asked by anonymous 12.11.2014 / 22:25

1 answer

1

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.

1. Remove the login form parameter

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" }))

2. Remove the Controllers parameters

    //
    // 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);
    }
    
31.01.2015 / 19:00