我想获得所有会话变量名称的列表.
就像是:
foreach(Key name in HttpContext.Session.Keys)
{
...
}
Run Code Online (Sandbox Code Playgroud)
你的代码有效!只是string不要使用Key
foreach (string key in Session.Keys)
{
var value = Session[key];
}
Run Code Online (Sandbox Code Playgroud)
或者另类
for (int i = 0; i < Session.Contents.Count; i++)
{
var key = Session.Keys[i];
var value = Session[i];
}
Run Code Online (Sandbox Code Playgroud)