2009-10-07 203 views
3

有誰知道爲什麼ASP.NET窗體身份驗證不能在Windows Safari瀏覽器上工作,或更好的,如何讓它的工作?這似乎是一個非常奇怪的問題。當我使用登錄控件(System.Web.UI.WebControls.Login)時,一切正常,但是如果我嘗試在調用FormsAuthentication.RedirectFromLoginPage safari時嘗試執行自定義Forms身份驗證登錄,只需將我發回登錄頁面,就好像我我沒有通過身份驗證,而其他瀏覽器都記錄了我的身份,並在我的途中發送給我。ASP.NET窗體身份驗證與Windows Safari

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

回答

1

嘗試要麼SetAuthCookie,或RedirectFromLoginPage。重定向需要知道重定向到哪裏(ReturnUrl),也許這就是你的問題。

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

這工作正常,我在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."; 
     } 

    }