C# 如何以编程方式更改网站级别的会话状态设置
我尝试使用以下代码将SessionState设置更改为InProcC# 如何以编程方式更改网站级别的会话状态设置,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
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配置