Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何以编程方式更改网站级别的会话状态设置_C#_Iis 7 - Fatal编程技术网

C# 如何以编程方式更改网站级别的会话状态设置

C# 如何以编程方式更改网站级别的会话状态设置,c#,iis-7,C#,Iis 7,我尝试使用以下代码将SessionState设置更改为InProc string configPath = "/Default Web site"; System.Configuration.Configuration config =System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( configPath); System.Web.Configuration.SessionStateSection ses

我尝试使用以下代码将SessionState设置更改为InProc

string configPath = "/Default Web site";
System.Configuration.Configuration config =System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( configPath);
System.Web.Configuration.SessionStateSection sessionSection = ( (System.Web.Configuration.SessionStateSection)config.GetSection( "system.web/sessionState" ) );
sessionSection.Mode = SessionStateMode.InProc;
sessionSection.AllowCustomSqlDatabase = false;
sessionSection.RegenerateExpiredSessionId = false;
sessionSection.Cookieless = System.Web.HttpCookieMode.UseCookies;
config.Save( );
但它不起作用。它不会抛出错误,但我看不到网站配置中的任何更改。当我查看config属性时,我看到并没有配置文件路径,并且hasFile被设置为false


如何在C#中修改此属性

是否尝试获取未放置在根文件夹中的web.config?请尝试使用ConfigurationManager.OpenExeConfiguration(文件名);修改,然后配置.Save();我正在尝试获取默认网站web配置,但我不知道它的物理位置,我希望此代码能够自动找到它。请尝试更改配置加载:
var configuration=WebConfigurationManager.OpenWebConfiguration(~”。不确定这是否会有任何区别,因为从未以编程方式更改过web.config。我正在从单机版应用程序加载它,因此“~”将找不到正确的web配置