2014-09-19 111 views
0

我使用的是asp.net,我对它很陌生。我的经理给我一个调试asp.net系统的任务。这个系统的问题之一是,当用户试图在文本框中写很长时间的细节时,会话将超时,并且最终用户没有完成输入的所有单词都将消失。所以当用户登录时,他们必须再次输入所有单词。asp.net会话超时同一页

所以我想问有没有什么方法可以在会话超时前临时保存文本?然后,当用户在会话超时后登录时,系统将直接返回到用户未管理完成写入的页面。在web.config中感谢,并为英语不好对不起......

回答

0

改变设置你的web.config页面

<system.web> 
    <sessionState timeout="480" /> 
</system.web> 
1

使用超时,也可以使用的时间跨度 - 20分钟默认情况下,也timeout属性不能设置为大于525,601分钟(1年)的进程和状态服务器模式的值。

<sessionState 
    mode="[Off|InProc|StateServer|SQLServer|Custom]" 
    timeout="number of minutes"............ 

    ....../> 
0

你需要重新登录

  1. 使用的定时器到你的页面控件的值保存到数据表后,以挽救 用户输入一次相同的信息,你可以按照这种方法进行
protected void Page_Load(object sender, EventArgs e) 
    { 

    System.Timers.Timer aTimer = new System.Timers.Timer(); 
    aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent); 
    aTimer.Interval=600000;//10 min timer 
    aTimer.Enabled=true; 
} 


DataTable table = new DataTable(); 
    private static void OnTimedEvent(object source, ElapsedEventArgs e) 
    { 
     // code to save data in datatable; 
     //like 
    table.Clear();//Refresh the table 
    table.Columns.Add("name", typeof(string));//No need to create column again and again.As i am doing here :| 
    table.Rows.Add(TextBox1.Text);//This is just sample code 
    } 

在每10分钟执行一段代码后,您的数据将被保存在数据表中。您也可以使用相同的数据表来保存数据库中的数据。

  1. 超时后,您的页面将被重定向到登录页面或其他页面。现在棘手的部分是当你在页面加载事件中重新登录时,只需检查数据表是否包含任何行 如果是,那么你必须从数据表中获取数据,然后再用数据填充控件。如果没有这意味着它是新鲜登录,不必做任何事情!
protected void Page_Load(object sender, EventArgs e) 
      { 
       if(table!=null) 
       if(table .Rows.Count>0) 
       { 
        Textbox1.Text=table.Row[0][0].ToString();//In this way you can fill controls again 
//And user need not to type data again!! 


    } 
       } 

所以这样你可以保留甚至在超时后由用户输入的数据。

对于理解数据表你可以按照这个链接Data table