2017-10-12 83 views
0

我創建MVC應用程序的MVC應用程序。在我有web.config.i.e會話過期問題

try 
{ 
    //// Helps to open the Root level web.config file. 
    Configuration webConfigApp = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); 
    AppSettingsSection objAppsettings = (AppSettingsSection)webConfigApp.GetSection("appSettings"); 
    //Edit 
    if (objAppsettings != null) 
    { 
     ////Modifying the AppKey from AppValue to AppValue1 
     objAppsettings.Settings["DaysToKeepJob"].Value = model.Keepjobsfolders.ToString(); 
     objAppsettings.Settings["DeleteLocalStoreStudies"].Value = model.DeleteLocalStoreStudies.ToString(); 
     objAppsettings.Settings["ManualBurnerNoOfCopies"].Value = model.ManualNumberofCopies.ToString(); 
     objAppsettings.Settings["DefaultBurner"].Value = model.DefaultBurner.ToString(); 
     objAppsettings.Settings["AutoBurnerNoOfCopies"].Value = model.AutoNumberofCopies.ToString(); 
     objAppsettings.Settings["SmartDisk"].Value = model.chkSMARTDisk.ToString(); 
     objAppsettings.Settings["ForcetodefaultTransfer"].Value = model.chkKeepjobsfolders.ToString(); 
     ////Save the Modified settings of AppSettings. 
     webConfigApp.Save(); 
    } 
    if (diskType.Title != null) 
    { 
     var res = DiskTypeSave(diskType); 
    } 
    return Json(new { Status = "Success", Msg = "Rules Saved Successfully." }, JsonRequestBehavior.AllowGet); 
} 

用於更新寫代碼,但該行webConfigApp.Save後();我的會話,即會話[「UserAccessRights」]變爲空。我知道,因爲更新web.config它得到空。

請提出來維護會話甚至web.config文件更新

+1

請勿修改您的web.config文件。將配置存儲在別處:單獨的JSON或XML文件,數據庫或鍵/值對存儲。 – mason

回答

2

每次更改web.config時,都會在IIS中重新啓動應用程序。

你可以做以下的事情之一:

  1. 使用其他的設置文件,XML,JSON等來存儲這些值
  2. 使用數據庫來存儲每個用戶的這些設置
  3. 使用SQL服務器保存會話或狀態服務器,而不是內存(默認)
0

對於這一點,你首先要保持會話複製到本地變量,然後再次分配。但爲此,您還必須保留Session.SessionId副本,因爲在新會話中它會再次設置。