3

I'm having problem with retunUrl what is duplicating my QueryString parameters.

My url is like:

"www.mysite.com/Order/?id=1&item=123"

then, redirect me to login page and the url look like:

"www.mysite.com/login/RedirectUrl=/Order?id=1&item=123&id=1&item=123"

After the user login, the action redirect to:

"www.mysite.com/Order/?id=1&item=123&id=1&item=123"

In my page when i use Request.QueryString["id"] i got an error, because the querystring "ID" is duplicated.

My login Action code look like this:

[HttpPost]
[AllowAnonymous]
public ActionResult Index(LoginModel model, string ReturnUrl)
{
    if(VerifyLogin(model))
    {
       if(ReturnUrl != null)
          return Redirect(ReturnUrl);//redirect to url with duplicated parameters
       else
          return Redirect("/Home");
    }
    else
    {
       ModelState.AddModelError("", "Invalid Username or Password");
    }

   return View();
}

How i can solve this problem?

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

I think problem is in Order controller or ReturnUrl assignment logic. It might adding url+queryString. If yes you can try something like Request.Url.GetLeftPart(UriPartial.Path) + queryString

sunil
  • 1
  • HI! thanks for your reply. Didnt work =(... Request.Url.GetLeftPart(UriPartial.Path) return "www.mysite.com" and Request.QueryString.ToString() return "RedirectUrl=/Order?id=1&item=123&id=1&item=123" because in that moment the querystring is the "RedirectUrl" – Fabio Draschi Morciani Sep 04 '13 at 11:57
  • **Try** [http://stackoverflow.com/questions/10802658/why-request-url-includes-querystring-in-it](http://stackoverflow.com/questions/10802658/why-request-url-includes-querystring-in-it). – sunil Sep 04 '13 at 14:49
  • thanks again, but it is not my case... i need the querystring, but i dont need duplicated querystring. I know how to get the first querystring even this is duplicated but i dont wanna do this for all of my pages... i have 20 + ... i need to solve this problem in the login Action. – Fabio Draschi Morciani Sep 04 '13 at 17:27