在 C# 中执行 bool 测试以确定是否启用 ASP.NET session 的最佳方法是什么?我不想使用 try-catch block 和 Sessions != null 抛出异常。
问候。
最佳答案
如果您使用 HttpContext.Current
,您将不会得到异常:
if(HttpContext.Current.Session != null)
{
// Session!
}
关于c# - 确定是否启用了 ASP.NET session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1336770/