有一个问题,我面临着我的托管公司,我使用的是使用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