none
ReturnUrl Duplicating Parameters - MVC 4 RRS feed

  • Question

  • 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?


    • Edited by Fabio DRM Tuesday, September 3, 2013 8:17 PM
    • Moved by Jason Dot Wang Wednesday, September 4, 2013 3:11 AM This thread is about ASP.NET
    Tuesday, September 3, 2013 7:56 PM

Answers

  • Why do'n you make this change

    From : return Redirect(ReturnUrl);//redirect to url with duplicated parameters

    To : return ReturnUrl;//redirect to url with duplicated parameters


    jdweng

    Wednesday, September 4, 2013 3:05 AM

All replies

  • If you drop a break point at the beginning of the Index method, does the value of your "ReturnUrl" already contain the duplicate parameters, or does it append them on the Redirect?

    Wednesday, September 4, 2013 2:26 AM
  • Why do'n you make this change

    From : return Redirect(ReturnUrl);//redirect to url with duplicated parameters

    To : return ReturnUrl;//redirect to url with duplicated parameters


    jdweng

    Wednesday, September 4, 2013 3:05 AM
  • Hi Fabio,

      Welcome to MSDN Forum Support.

      You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 4, 2013 3:11 AM
  • ReturnUrl already contains duplicated parameters

    =(

    Wednesday, September 4, 2013 12:01 PM
  • Can't do this, because the method expect a "ActionResult" with a return value. ReturnUrl is just a string, i need use return Redirect(returnUrl) to make it work.
    Wednesday, September 4, 2013 12:04 PM
  • Wednesday, September 4, 2013 12:22 PM