2014-09-19 34 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