会话在MVC应用程序中出现过期问题

时间:2017-10-12 13:57:28

标签: c# asp.net-mvc asp.net-mvc-4

我已经创建了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它会变为null。

请建议维护会话甚至web.config更新

2 个答案:

答案 0 :(得分:2)

每次更改web.config时,都会在IIS中重新启动应用程序。

您可以执行以下操作之一:

  1. 使用其他设置文件,xml,json等来存储这些值
  2. 使用数据库存储每个用户的设置
  3. 使用SQL Server保存会话或状态服务器,而不是内存(默认)

答案 1 :(得分:0)

为此,您首先必须将Sessions副本保存到本地变量中,然后再次分配。但是为此你必须保留Session.SessionId副本,因为在新会话中它再次设置。

相关问题