Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble with Asp.net MVC passing in a querystring as a parameter
    text
    copied!<p>I have a login page. In my web.config I setup a loginUrl so that if a user tries to go to an "Authorized" page and are not authorized they will get redirected to the login page.</p> <p>Now I noticed when this happens and the user gets redirected from a "Authorized" page the url from the page they are getting redirected from gets appended to the login url. </p> <p>So that way when they do login I can use that I can send them back to the page they where trying to get too.</p> <p>So this is how the Url would look:</p> <p><a href="http://localhost:2505/CMS_Account/LogOn?ReturnUrl=%2fCMS_Home%2fIndex" rel="nofollow noreferrer">http://localhost:2505/CMS_Account/LogOn?ReturnUrl=%2fCMS_Home%2fIndex</a> </p> <p>So I am trying to capture the ReturnUrl querystring part as a parameter in my View.</p> <p>But I can't get it took work. </p> <p>So I found out if I change my Form for the login to this:</p> <pre><code>&lt;% using (Html.BeginForm()) ........ </code></pre> <p>Then I can capture the ReturnURl for some reason no problem.</p> <p>However how I have it right now I have this:</p> <pre><code>&lt;% using (Html.BeginForm("Login","Authentication",FormMethod.Post,new { id = "frm_Login"})) ..... </code></pre> <p>Once I try to pass the parameters into the BeginForm it stops capturing the ReturnUrl.</p> <p>I don't know why it stops. Some people say that it is because I am using the default route and somehow if you don't put anything in the beingForm it magically can figure out the ReturnUrl with the default url.</p> <p>Soon as you put something in BeginForm it seems to get dumb and you need to give it a route to tell it what to do.</p> <p>I don't know how to write this route though. I tried quite a few different combinations and they all failed and everyone who tells me right a route never tell me how it should look like. </p> <p>So I don't know what to try anymore.</p> <p>What I tried</p> <pre><code>routes.MapRoute( "CMS_Account", // Route name "CMS_Account/{action}/{ReturnUrl}", // URL with parameters new { controller = "CMS_Account", action = "LogOn",} // Parameter defaults ); routes.MapRoute( "CMS_Account", // Route name "CMS_Account/{action}/{ReturnUrl}", // URL with parameters new { controller = "CMS_Account", action = "LogOn", ReturnUrl = ""} // Parameter defaults ); routes.MapRoute( "CMS_Account", // Route name "{controller}/{action}/{ReturnUrl}", // URL with parameters new { controller = "CMS_Account", action = "LogOn", ReturnUrl = ""} // Parameter defaults ); routes.MapRoute( "CMS_Account", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "CMS_Account", action = "LogOn", id = ""} // Parameter defaults ); routes.MapRoute( "CMS_Account", // Route name "{controller}/{action}/", // URL with parameters new { controller = "CMS_Account", action = "LogOn"} // Parameter defaults ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload