有一個問題,我面臨着我的託管公司,我使用的是使用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。
會話狀態數據庫存儲免去您的上市配置應該沒有任何影響的窗體身份驗證票。 – 2011-02-28 22:05:48