9

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=test

Once my user is authenticated I want to Redirect to the 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"]);

    }
}
1

3 Answers 3

2

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:

  1. I create a copy of the LogOn.csthml as LogOn.Mobile.cshtml
  2. 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

Sign up to request clarification or add additional context in comments.

Comments

0
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);

    }
}

1 Comment

See my comment in the code, the url is always correct, the jQuery Mobile framework changes the browser url as noted in the question.
0

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.

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.