请问各位大侠,我用asp.net做了一个网站,用cookie保存登陆信息。失效时间设为1天。但是现在十几分钟不对网页操作她就提示要重新登陆,请问这是怎么回事,改怎么把时间延长了呢?谢谢

解决方案 »

  1.   

    其它方法也保存了用户信息 比如session
      

  2.   

    web。config可以设置失效的时间
      

  3.   

    设置一下session 的timeout 默认是20分钟
      

  4.   

    如果SESSION没了,看有COOKIE没,有了重加进了,都没再提示。
      

  5.   

    Cookie存在安全性问题;Session占内存,设置一下会话时间!
      

  6.   

    要看你的登录身份认证是用的是那种方法....  如果是自己写的登录,用session保存的话,我想按上面人说的,应该可以,如果是 用VS 自带的配置管理工具  登录控件来进行身份认证的,应该要到web.config里进行设置.... 
      

  7.   

    在web.config里加个节设置时间    <sessionState mode="InProc" timeout="120"/>
      

  8.   

    我在webconfig中加了<sessionState mode="InProc" timeout="1"/>等了一分钟还是能操作,证明1分钟后没有失效啊。我在IIs中也设置了会话时间位1分钟,也是不行
      

  9.   

    学习
    好像session丢失的情况不少啊
      

  10.   

    你说的是用cookie保存,根据你的描述,你实际上是用session来保存的.
      

  11.   

    这是登陆界面确定按钮的代码,麻烦大家给看看string strUserName, strPwd;
                strUserName = TxtUserName.Text.Trim();
                strPwd = TxtPwd.Text.Trim();
                //判断数据库中该用户是否存在
                if (obj.IsExistUserName(strUserName) == false)
                {
                    Label1.Visible = true;                     //如果该用户不是合法用户,则显示label1
                    
                    return;
                }
                if (Confirm(strUserName, strPwd))
                {                //FormsAuthentication.RedirectFromLoginPage(strUserName,false);
                    //利用FormsAuthentication实现Form身份验证
                    //同时登录时建立登录信息的Cookie
                    //并在Cookie中保留身份验证信息,使登录后不再
                    //需要重新提交身份验证信息
                    FormsAuthentication.SetAuthCookie(strUserName, true);
                    //FormsAuthentication.SetAuthCookie(strPwd,true);                HttpCookie cookie1 = new HttpCookie("UserName");       //建立HttpCookie的实例
                    //HttpCookie cookie2=new HttpCookie("PassWord");                cookie1.Values["UserName"] = strUserName;
                    //cookie2.Values["PassWord"]=strPwd;                cookie1.Expires = DateTime.Now.AddDays(1); //获取或设置此cookie过期时间,保存Cookie一天
                    //cookie2.Expires=DateTime.Now.AddDays(1);                Response.Cookies.Add(cookie1);    //将实例加入到HttpResponse的cookies集合中,以便以后使用
                    //Response.Cookies.Add(cookie2);
                    
                    Response.Redirect("index.aspx");
                }
                else
                {
                    Label1.Visible = true;
                    return;
                }
      

  12.   

    在web.config里面把会话时间重新设置一下
      

  13.   

    Session.TimeOut=你希望过期的时间(分)
      

  14.   

    我在webconfig中是这样设置的:
    <system.web>
        <sessionState mode="InProc" timeout="900" />
        
        
        <httpRuntime executionTimeout="8000" maxRequestLength="5120" />
    <!-- 
                设置 compilation debug="true" 将调试符号插入
                已编译的页面中。但由于这会 
                影响性能,因此只在开发过程中将此值 
                设置为 true。
            -->
    <httpHandlers>
       <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        validate="false" />
      </httpHandlers>
      <compilation debug="true">
       <assemblies>
        <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
       </assemblies>
       <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       </buildProviders>
      </compilation>
    <!--
                通过 <authentication> 节可以配置 ASP.NET 使用的 
                安全身份验证模式,
                以标识传入的用户。 
            -->
    <authentication mode="Forms"/>
        
    <!--
                如果在执行请求的过程中出现未处理的错误,
                则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
                开发人员通过该节可以配置
                要显示的 html 错误页
                以代替错误堆栈跟踪。
    -->
            <customErrors mode="On" defaultRedirect="systemerror.aspx">
            </customErrors>
            
    </system.web>
    在登陆界面确定按钮中的程序中加入如下代码:Session.Timeout = 900;请问这样可以吗?
      

  15.   

    我在webconfig中是这样设置的: 
    <system.web> 
        <sessionState mode="InProc" timeout="900" /> 
        
        
        <httpRuntime executionTimeout="8000" maxRequestLength="5120" /> 
    <!-- 
                设置 compilation debug="true" 将调试符号插入 
                已编译的页面中。但由于这会 
                影响性能,因此只在开发过程中将此值 
                设置为 true。 
            --> 
    <httpHandlers> 
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
        validate="false" /> 
      </httpHandlers> 
      <compilation debug="true"> 
      <assemblies> 
        <add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
      </assemblies> 
      <buildProviders> 
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
      </buildProviders> 
      </compilation> 
    <!-- 
                通过 <authentication> 节可以配置 ASP.NET 使用的 
                安全身份验证模式, 
                以标识传入的用户。 
            --> 
    <authentication mode="Forms"/> 
        
    <!-- 
                如果在执行请求的过程中出现未处理的错误, 
                则通过 <customErrors> 节可以配置相应的处理步骤。具体说来, 
                开发人员通过该节可以配置 
                要显示的 html 错误页 
                以代替错误堆栈跟踪。 
    --> 
            <customErrors mode="On" defaultRedirect="systemerror.aspx"> 
            </customErrors> 
            
    </system.web> 
    在登陆界面确定按钮中的程序中加入如下代码: Session.Timeout = 900; 请问这样可以吗?
      

  16.   

    i did learnt something from this topic 
      

  17.   

    不要在cookie中保存过多数据内容。你可以把用户名、密码,以及所有其它信息,都保存在后台数据库甚至文件中,保存时记得这些后台信息都增加一个关键索引字段SessionID,对应的值用页面的Session.SessionID填入。因为这个SessionID是不会丢失的(甚至即使客户端禁用Cookie也不会丢失)。有时候说不要使用Session而要使用Cookie,实际上SessionID就是这个使用Cookie的含义,而且更加强大。
      

  18.   

    SESSION的用法,在百度上查查就可知道了。
      

  19.   

    在配置文件下设置下session <sessionState mode="InProc" timeout="120"/>
      

  20.   

    问题解决了,在webconfig中如此设置就好用了:
    <authentication mode="Forms">
          <forms name="auth" loginUrl="default.aspx" timeout="60"></forms>
        </authentication>定义了60分钟。60分钟不操作就需要重新登录了。
    谢谢大家的回答。