Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad/iPhone Chrome - Auth Cookie not setting over jquery post (ajax) - MVC 3

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...

like image 838
Rob Avatar asked Jul 04 '12 08:07

Rob


1 Answers

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>
like image 87
Froyke Avatar answered Sep 18 '22 00:09

Froyke