Authenticate ASP.NET forms with Safari for Windows

Does anyone know why ASP.NET Forms Authentication does not work on Windows Safari, or better yet, how to make it work? This seems like a very strange problem. When I use the login control (System.Web.UI.WebControls.Login) everything works fine, but if I try to do user login to authenticate the forms, when I call FormsAuthentication.RedirectFromLoginPage, safari just sends me back to the login page. as if I'm not authenticated, while every other browser logs me in and sends me in my path.

protected void lnkLogin_Click(object sender, EventArgs e)
{
    if (Membership.Provider.ValidateUser(txtUsername.Text, txtPassword.Text))
    {
        Session.Clear();
        HttpContext.Current.Response.Cookies.Clear();
        FormsAuthentication.SetAuthCookie(txtUsername.Text, true);
        FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true);
    }
}
+3
source share
2

SetAuthCookie, RedirectFromLoginPage. , (ReturnUrl), , .

    if (Request.QueryString["ReturnUrl"] != null) 
    { 
        FormsAuthentication.RedirectFromLoginPage("someuserid", false); 
    } 
    else 
    { 
        FormsAuthentication.SetAuthCookie("someuserid", false); 
        Response.Redirect("~/SomePage.aspx"); 
    } 
+1

Safari:

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        //check login
        User user = UserBAL.GetUser(Login1.UserName, Login1.Password);

        //null and filled object check
        if (user != null && user.Id > 0 && user.Roles != null && user.Roles.Count > 0)
        {

            e.Authenticated = true;

            FormsAuthenticationTicket authTicket = new
            FormsAuthenticationTicket(1,                          //version
                                     Login1.UserName,           // user   name
                                     DateTime.Now,               // creation
                                     DateTime.Now.AddMinutes(60),//  Expiration
                                     false,                      // Persistent
                                     string.Join("|", user.Roles.ToArray())); // User ata


            // Now encrypt the ticket.
            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            // Create a cookie and add the encrypted ticket to the
            // cookie as data.
            HttpCookie authCookie =
                         new HttpCookie(FormsAuthentication.FormsCookieName,
                                        encryptedTicket);

            Response.Cookies.Add(authCookie);

            //redirect 
            Response.Redirect(FormsAuthentication.GetRedirectUrl(
                                           Login1.UserName,
                                           false));

        }
        else
        {

            Login1.FailureText = "Login failed.";
        }

    }
0

Source: https://habr.com/ru/post/1719510/


All Articles