9

I'm having trouble with Chrome on the iPad/iPhone with what I thought was a simple enough task and works on Chrome Desktop (Mac & PC) and Safari on iPad/iPhone.

I have the following jquery on my page:

$("#login-login-button").click(function () { var username = $("#Username").val(); var password = $("#Password").val();

    $("#login-loading-icon").show();

    $.post("/login", { username: username, password: password }, function (data, response) {
        if (response == "success") {
            if (data.IsValid) {
                window.location.href = "/profile";
            }
            else {
                $("#login-error-message").html(data.ErrorMessage);
                $("#login-loading-icon").hide();
            }
        }
        else {
            alert("An error occurred, please try again.");
        }
    });
});

And the Controller Action is code looks like this:

[HttpPost]
public JsonResult Index(string username, string password)
{
        AjaxResponseModel ajaxResponseModel = new AjaxResponseModel();

        User user = UserDAL.Select(username, Hash.MD5(password));

        if (user != null)
        {
            if (!user.IsVerified.Value)
            {
                ajaxResponseModel.AddErrorMessage("Account not verified.");
            }
            else if (!user.IsActive.Value)
            {
                ajaxResponseModel.AddErrorMessage("Your account is not active.");
            }
            else
            {
                FormsAuthentication.SetAuthCookie(username, false);
            }
        }
        else
        {
            ajaxResponseModel.AddErrorMessage("Login details incorrect.");
        }

        return Json(ajaxResponseModel);
    }

I've tried setting the Auth Cookie via a non-ajax request but it's not working either.

And I've discovered that on the iPad/iPhone if I use the "Request Desktop Site" in the Chrome menu the problem disappears however there is no concept of mobile/desktop on my site at this point i.e. what Chrome gets the first time should be the Desktop site...

1
  • 1
    I've since discovered that this is a bug in .Net and is supposed to be fixed in version 4.5 however the solution from @Froyke is still a quick and easy work-around.
    – Rob
    Feb 12, 2013 at 5:14

1 Answer 1

6

Was already ansewerd here: Asp.Net Forms Authentication when using iPhone UIWebView

I used the default config which is more reasonable given current browsers distribution.

<browsers>
  <browser refID="Default"> 
    <capabilities> 
      <capability name="cookies" value="true" /> 
    </capabilities>
  </browser>
</browsers>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.