Get session cookie name

Can I get a session cookie name at a medium trust level? The code below works fully, but generates a security exception at the medium trust level.

string sessionCookieName = ((SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState")).CookieName;
+3
source share
1 answer

You can use the HTTP_COOKIE server variable from the Request object to get the cookie string that was included in the request.

string cookieString = Request.ServerVariables["HTTP_COOKIE"]

If you want to get the session cookie name from 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"  />        

web.config, :

public static bool SessionCookieName
{
    get { return ConfigurationManager.AppSettings["SessionCookieName"]; }
} 
+1

Source: https://habr.com/ru/post/1777594/


All Articles