2

I have a certain situation where the ActionResult method in a controller needs to do a Redirect if a Returnurl is provided.

However, how can I append a querystring to that and still use:

return Redirect(url) ?

everytime I do this, I always get a security exception that the request had a potentially dangerous value (the ampersand or even the question mark).

2 Answers 2

4

Try this,filling in the name of the action and controller as appropriate:

System.Web.Routing.RouteValueDictionary rvd = new System.Web.Routing.RouteValueDictionary();
foreach(string key in HttpContext.Request.QueryString.AllKeys)
{
    rvd.Add(key, HttpContext.Request.QueryString[key]);
}

return RedirectToAction("MyAction", "MyController", rvd);
Sign up to request clarification or add additional context in comments.

3 Comments

That wouldn't work because this wouldn't be a RedirectToAction - just a pure MVC Redirect
Are you trying to redirect to a non-mvc url?
not quite. whilst it is within the MVC site, there will be a redirect to different areas depending on the returnUrl passed into the page. THAT is the url I want to redirect to after the action is "completed". Please see my answer below this comment (answer to be made tomorrow) - I used Url.Content in conjunction with the returnUrl and also the querystring I wanted to pass along with it.
-1

forgot - I used Url.Content and now it works just fine.

return Redirect(Url.Content(model.ReturnUrl + otherPotentialQueryStringHere)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.