Why Request.QueryString["ReturnUrl"] returning NULL even if it is present in the URL?

asp.net, asp.net-mvc, query-string

Solution

Try debugging the code - you should be able to see in the debugger the entire list of QueryString parameters, so you can see if you miss-spelt it.

Problem

(This is a more narrow question) In my asp.net MVC action, I am looking if the ReturnUrl value is in the URL. My Url looks like this: ``` http://localhost:56112/user/login?ReturnUrl=/user/settings ``` In my action, I am looking if that querystring value exists, and it is returning NULL?? How can this be? The code: ``` if(Request.QueryString["ReturnUrl"] != null) { } ``` Tracing through the application, it is just skipping the if statement's body i.e. it is NULL. How can this be explained? Update In the controller that checks if the user has logged in, I have a ActionFilter that looks like: ``` public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); // some stuff string loginUrl = FormsAuthentication.LoginUrl + "/user/settings; context.Response.Redirect(loginUrl); } ```

Original source