目前,我有2种方法:
cookieless="UseCookies"
时,我的网址看起来像:http://example.com/Stuff
<sessionState timeout="60" cookieless="UseCookies"/>
cookieless="true"
时,我有这样的网址http://example.com/%28S%28uanyuxwgaviyonky0lxwq3vq%29%29/Stuff
<sessionState timeout="60" cookieless="true"/>
我可以将
cookieless
属性设置为动态吗?就像是if(/*condition*/)
{
sessionState .cookieless = "true";
}
else
{
sessionState .cookieless = "UseCookies";
}
这必须在Global.asax的
SessionStart
中的某处 最佳答案
这里的基本思想是您想在运行时修改WebConfig
文件。我没有尝试过自己,但是出于好奇,我通过互联网搜索了This link
根据此,您在Global.asax
中的代码将类似于
注意:这实际上将新值写入web.config
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Configuration config;
config = WebConfigurationManager.OpenWebConfiguration("~");
SessionStateSection SessionState = config.GetSection("system.web/sessionState") as SessionStateSection;
if (SessionState != null)
{
SessionState.Mode = System.Web.SessionState.SessionStateMode.InProc;// changes
if (true/*condition*/)
{
SessionState.Cookieless = System.Web.HttpCookieMode.UseCookies;
}
else
{
SessionState.Cookieless = System.Web.HttpCookieMode.UseUri; // not sure about this one
}
config.Save();
}
}