ASP.NET Response.Redirect with jQuery Mobile - Url hashing
I have a standard forms auth ASP.NET application. My Registration and Login page are in the same .aspx file with 2 jQuery Mobile pages. If I postback my ASP.NET page, such as the user fails to login correctly...etc The Url hash starts appending to itself over and over.
Example Url:
http://localhost:56644/Register.aspx?ReturnUrl=%2fDefault.aspx%3fbla%3dtest&bla=test#Register.aspx?ReturnUrl=%2fDefault.aspx%3fbla%3dtest&bla=testOnce my user is authenticated I want to Redirect to the 开发者_JAVA技巧ReturnUrl without all the hash information or find a way for the url to remain during postbacks?
Markup:
<div data-role="page" id="register">
<div data-role="content" data-scroll="true" data-theme="b" class="Content">
......
<a href='#login'>Login</a
</div>
</div>
<div data-role="page" id="login">
<div data-role="content" data-scroll="true" data-theme="b" class="Content">
.....
<a href='#register' >Registered Yet?</a>
</div>
</div>
Code-behind on Register.aspx:
protected void btnLogin_Click(object sender, EventArgs e)
{
if (LoggedIn)
{
FormsAuthentication.SetAuthCookie("blabla", true);
//Note: Request.QueryString["ReturnUrl"] = "/Default.aspx?bla=test";
Response.Redirect(Request.QueryString["ReturnUrl"]);
}
}
This is an old post but having experienced the same issue I'll post the solution I have worked out - it is a bit rough but it may help someone or be improved. Moreover it is in ASP.NET MVC 4 - not sure how to migrate the same code to aspx
What I am basically doing is capturing the RedirectTo URL and using it to provide as data-url
attribute of the LogOn form tag.
In other terms, in MVC 4:
- I create a copy of the LogOn.csthml as LogOn.Mobile.cshtml
in LogOn.Mobile.cshtml I add the following: :
@{ string landPage = Request.Url.Query.Length>11? Request.Url.Query.Substring(11):"";//very rough, to be improved. // Here I am clipping the RedirectTo prefix of the Query } //replaces the boilerplate @using (Html.BeginForm()) @using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @data_url = landPage}))
This should enough to make it work
protected void btnLogin_Click(object sender, EventArgs e)
{
if (LoggedIn)
{
FormsAuthentication.SetAuthCookie("blabla", true);
//Note: Request.QueryString["ReturnUrl"] = "/Default.aspx?bla=test";
// This will get only the first instance of ReturnUrl
var url = Request.Url.PathAndQuery.Substring(
Request.Url.PathAndQuery.IndexOf("ReturnUrl=") + ("ReturnUrl=").Length);
Response.Redirect(url);
}
}
Jquery Mobile is designed to only have one page and use #page to load via ajax the page you want to go to.
from what i can see its trying to append its method of indicating the page our on thus the #Register.aspx its adding to the end.
My solution for this problem was to use usercontrols for the different mobile sections of my site and i used ajax for anything that would have normally been a postback.
精彩评论