1
How to remove querystring Returnurl from my Login page ?
1
How to remove querystring Returnurl from my Login page ?
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.
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" }))
//
// 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 asp.net-mvc-5
You are not signed in. Login or sign up in order to post.
You are using
FormsAuthentication
?– Leonel Sanches da Silva
@Ciganomorrisonmendez, I’m using Asp.net Identity
– Rod
@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!
– Marconi
Favorite. I answer with more time.
– Leonel Sanches da Silva