locked
ReturnUrl Duplicating Parameters - MVC 4 RRS feed

  • Question

  • User2066740583 posted

    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 with duplicated parameters

                           else

                                     return Redirect("/Home");

                  }

                  else

                           ModelState.AddModelError("", "Invalid Username or Password");

                 return View();

    }

    How i can solve this problem?
    Wednesday, September 4, 2013 8:12 AM

Answers

  • User-417640953 posted

    Hi fabiodrm,

    Based on your description, I got that your url parameters are duplicating in mvc4 project.

    For this issue, I think you are using IIS Url Rewrite module. If so please set the appendQueryString as false like below.

    <rule name="Company Category">
    <match url="company_category/([0-9]+)/(?:[^/]*)/?" />
    <action type="Rewrite" url="company_search.aspx?cat={R:1}" appendQueryString="true" />
    </rule>

    Similar issue.

    http://forums.iis.net/t/1176016.aspx

     

    Hope this helps, thanks.

     

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2013 9:46 PM

All replies

  • User1262634031 posted

    I think you attach parametes to

    www.mysite.com/Order

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

    but somewhere in your code you again attach parameters to this ("www.mysite.com/Order/?id=1&item=123") resulted url 

    Wednesday, September 4, 2013 8:24 AM
  • User2066740583 posted

    i dont attach querystring again to the url!

    if i put break point in the begining of the Action, returnUrl already contains duplicated parameter.

    Wednesday, September 4, 2013 8:26 AM
  • User-417640953 posted

    Hi fabiodrm,

    Based on your description, I got that your url parameters are duplicating in mvc4 project.

    For this issue, I think you are using IIS Url Rewrite module. If so please set the appendQueryString as false like below.

    <rule name="Company Category">
    <match url="company_category/([0-9]+)/(?:[^/]*)/?" />
    <action type="Rewrite" url="company_search.aspx?cat={R:1}" appendQueryString="true" />
    </rule>

    Similar issue.

    http://forums.iis.net/t/1176016.aspx

     

    Hope this helps, thanks.

     

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 9, 2013 9:46 PM