获取会话cookie的名字 [英] Get session cookie name
问题描述
是否有可能在中等信任级别来获得会话cookie的名字吗?下面的code工作在完全信任,但抛出中等信任级别安全异常。
字符串sessionCookieName =((SessionStateSection)WebConfigurationManager.GetSection(System.Web程序/的sessionState))CookieName。
您可以使用 HTTP_COOKIE服务器变量从Request对象,以获得所包含的请求的cookie字符串。
字符串cookieString = Request.ServerVariables [HTTP_COOKIE]
如果你想要的是从web.config中获取会话cookie的名字,你为什么不添加在的appSettings 包含会话cookie名节一个简单的入门STRONG>
<&的appSettings GT;
<添加键=SessionCookieNameVALUE =__ SessionCookieName/>
< appSetting> <的sessionState cookieName =__ SessionCookieName/>
然后,您可以通过以下code读取web.config中设置值:
公共静态布尔SessionCookieName
{
{返回ConfigurationManager.AppSettings [SessionCookieName]; }
}
Is it possible to get session cookie name in medium trust level? The code below works in full trust, but throws a security exception in medium trust level.
string sessionCookieName = ((SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState")).CookieName;
You can use HTTP_COOKIE server variable from the Request object, to get the cookie string that was included with the request.
string cookieString = Request.ServerVariables["HTTP_COOKIE"]
If what you want is to obtain the session cookie name from the web.config, why don't you add a simple entry in the appSettings section containing the session cookie name?
<appSettings>
<add key="SessionCookieName" value="__SessionCookieName"/>
<appSetting>
<sessionState cookieName="__SessionCookieName" />
Then you can read the web.config setting value by using the following code:
public static bool SessionCookieName
{
get { return ConfigurationManager.AppSettings["SessionCookieName"]; }
}
这篇关于获取会话cookie的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!