How to remove querystring Returnurl?

Asked

Viewed 286 times

1

How to remove querystring Returnurl from my Login page ?

  • You are using FormsAuthentication?

  • @Ciganomorrisonmendez, I’m using Asp.net Identity

  • @I use it and I have the same problem! It generates the following url http://localhost:50553/Default.aspx? Returnurl=%2fius%2fCadastroLocation.aspx Could you answer the question please!

  • Favorite. I answer with more time.

1 answer

1


I do not recommend doing this because it is a major loss of functionality (in case, redirect the user to the page from which it came and which was not authorized), but I will demonstrate how to remove.

1. Remove the parameter from the login form

In the archive Views/Account/Login.cshtml, the line that generates the form should look something like this:

@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))

Modify to:

@using (Html.BeginForm("Login", "Account", null, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))

2. Remove Controller 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);
    }
  • in the example you explain how to remove, and there is some way to change?

  • @Rod What you would like to change?

  • the parameter that is in the login url? returnurl= change this returnurl to anything else, I tried to change the viewbag and parameter names, but it seemed useless unless I did something wrong

  • To change vc you need to modify where @Ciganomorrisonmendez quoted to remove and include in startup.auth.Cs app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(("/account/login")), ReturnUrlParameter = "url-de-retorno" });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.