Hi
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.
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.
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.
So this is how the Url would look:
http://localhost:2505/CMS_Account/LogOn?ReturnUrl=%2fCMS_Home%2fIndex
So I am trying to capture the ReturnUrl querystring part as a parameter in my View.
But I can't get it took work.
So I found out if I change my Form for the login to this:
<% using (Html.BeginForm()) ........
Then I can capture the ReturnURl for some reason no problem.
However how I have it right now I have this:
<% using (Html.BeginForm("Login","Authentication",FormMethod.Post,new { id = "frm_Login"})) .....
Once I try to pass the parameters into the BeginForm it stops capturing the ReturnUrl.
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.
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.
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.
So I don't know what to try anymore.
What I tried
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
);