Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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
Asp.net 如何读取web.config中的会话状态信息_Asp.net_Vb.net_Session_Web Config_Session State - Fatal编程技术网

Asp.net 如何读取web.config中的会话状态信息

Asp.net 如何读取web.config中的会话状态信息,asp.net,vb.net,session,web-config,session-state,Asp.net,Vb.net,Session,Web Config,Session State,我在web.config中配置了会话状态 <sessionState cookieless="AutoDetect" timeout="5" sqlConnectionString="....."/> 现在,我想从代码隐藏中了解超时和sqlConnectionString。请帮帮我。您可以使用来了解超时值 然而,更好的方法是使用配置API来读取配置。在这种情况下,请使用下面给出的代码获取对和的引用,然后使用和等属性查找必要的配置值 using System.Web.Config

我在web.config中配置了会话状态

<sessionState cookieless="AutoDetect" timeout="5" sqlConnectionString="....."/>

现在,我想从代码隐藏中了解超时和sqlConnectionString。请帮帮我。

您可以使用来了解超时值

然而,更好的方法是使用配置API来读取配置。在这种情况下,请使用下面给出的代码获取对和的引用,然后使用和等属性查找必要的配置值

using System.Web.Configuration;

...

var sessionSection = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState");
您可以使用此代码

Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.config");
SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");