2014-06-23 27 views
2

在.cshtml頁面上顯示所有會話變量的最佳方式是什麼?顯示.cshtml頁面上的所有會話變量

使用

@HttpContext.Current.Session(); 

試過但是這並沒有顯示任何東西。

+0

看到http://www.xyzws.com/JSPfaq/how-to-display-all-the-session-variables-in-an-html -page/33 –

回答

5

這是未經測試,但應該工作:

@{ var session = HttpContext.Current.Session; } 
@foreach (string key in session.Keys) { 
    <p>Key: @key - Value: @session[key].ToString()</p> 
} 
+0

完美!效果很好 –