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