我怎么能看在web.config中会话状态信息 [英] How could I read session state information in web.config

查看:162
本文介绍了我怎么能看在web.config中会话状态信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I configured session state in web.config.

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

现在,我想知道从code-背后超时和sqlConnectionString。请帮我。

Now, I want to know timeout and sqlConnectionString from code-behind. Please, help me.

推荐答案

您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.timeout.aspx\">Session.Timeout要知道超时值。

You can use Session.Timeout to know timeout value.

然而,更好的办法是使用配置API来读取配置。在这种情况下,使用code下面给出获得参考<一href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.sessionstatesection.aspx\">session国家配置,然后使用属性,如<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.sessionstatesection.sqlconnectionstring.aspx\">SqlConnectionString和<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.sessionstatesection.timeout.aspx\">Timeout找到必要的配置值。

However, better way is to use configuration API to read configuration. In this case, use code given below to get reference to session state configuration and then use properties such as SqlConnectionString and Timeout to find the necessary configured values.

using System.Web.Configuration;

...

var sessionSection = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState");

这篇关于我怎么能看在web.config中会话状态信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆