0

有一個問題,我面臨着我的託管公司,我使用的是使用FormsAuthentication的項目,問題是雖然它成功登錄,但它非常快速地註銷,並且我不知道可能是什麼原因即, 所以在我的web.config文件,我增加這些線路:表單身份驗證快速註銷,本地工作正常!

<authentication mode="Forms" > 
    <forms name="Nadim" loginUrl="Login.aspx" defaultUrl="Default.aspx" protection="All" path="/" requireSSL="false"/> 
</authentication> 
<authorization> 
    <deny users ="?" /> 
</authorization> 


<sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" cookieless="false" timeout="1440"> 
</sessionState> 

,這是我的代碼在我的自定義登錄頁面使用:

protected void PasswordCustomValidator_ServerValidate(object source, ServerValidateEventArgs args) 
    { 
     try 
     { 
      UsersSqlDataSource.SelectParameters.Clear(); 
      UsersSqlDataSource.SelectCommand = "Select * From Admins Where AdminID='" + IDTextBox.Text + "' and Password='" + PassTextBox.Text + "'"; 
      UsersSqlDataSource.SelectCommandType = SqlDataSourceCommandType.Text; 

      UsersSqlDataSource.DataSourceMode = SqlDataSourceMode.DataReader; 

      reader = (SqlDataReader)UsersSqlDataSource.Select(DataSourceSelectArguments.Empty); 
      if (reader.HasRows) 
      { 
       reader.Read(); 
       if (RememberCheckBox.Checked == true) 
        Page.Response.Cookies["Admin"].Expires = DateTime.Now.AddDays(5); 
       args.IsValid = true; 

       string userData = "ApplicationSpecific data for this user."; 

       FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket(1, IDTextBox.Text, System.DateTime.Now, System.DateTime.Now.AddMinutes(30), true, userData, FormsAuthentication.FormsCookiePath); 
       string encTicket = FormsAuthentication.Encrypt(ticket1); 
       Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); 
       Response.Redirect(FormsAuthentication.GetRedirectUrl(IDTextBox.Text, RememberCheckBox.Checked)); 

       //FormsAuthentication.RedirectFromLoginPage(IDTextBox.Text, RememberCheckBox.Checked); 
      } 
      else 
       args.IsValid = false; 

     } 
     catch (SqlException ex) 
     { 
      ErrorLabel.Text = ex.Message; 
     } 
     catch (InvalidOperationException) 
     { 
      args.IsValid = false; 
     } 
     catch (Exception ex) 
     { 
      ErrorLabel.Text = ex.Message; 
     } 

而且你會發現,行代碼: FormsAuthentication.RedirectFromLoginPage(IDTextBox.Text,RememberCh eckBox.Checked); 被評論,因爲我認爲有可能是錯誤的機票,當我登錄,所以我創建它手動,每一件事我知道我嘗試過但沒有任何工作, 所以沒有人有任何想法是什麼問題? 在此先感謝, Baher。

回答

-1

我認爲你的問題可能在stateConnectionString =「tcpip = localhost:42424」也許你需要爲你的提供者設置一個不同的URL。

+0

會話狀態數據庫存儲免去您的上市配置應該沒有任何影響的窗體身份驗證票。 – 2011-02-28 22:05:48

0

您正在修改不需要修改的內容。

取出Response.Redirect(FormsAuthentication線,取消重定向,並嘗試與

<authentication mode="Forms" /> 
<authorization> 
    <deny users ="?" /> 
</authorization> 
<sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" cookieless="false" timeout="1440"/> 
+1

當我問託管公司中的人時,他們是誰給了我那行 即使他們告訴我改變模式從Inproc到狀態服務器,並給了我狀態連接字符串 – Baharanji 2010-04-25 11:20:00

+1

@user - 好的,我站在糾正。儘管如此,試試其餘的。 – 2010-04-25 11:26:03