【发布时间】:2014-01-16 18:15:55
【问题描述】:
我想在我的 ASP.NET 网站 (WebForms) 中检查会话的值。 所以我尝试做的是:
// This file called 'Encryptor.cs' and is located under the 'App_Code' folder.
using System;
using System.Data;
using System.Data.OleDb;
using System.Security.Cryptography;
using System.Text;
public static class Encryptor
{
public static bool CheckLoginStatus()
{
bool LoginStatus = false;
if ((string)Session["username"] == null)
{
LoginStatus = true;
}
return LoginStatus;
}
}
我不断收到此消息:“名称 'Session' 在当前上下文中不存在。” 我该如何解决?
【问题讨论】:
-
查看这篇文章:How to access session variables from any class in ASP.NET? 接受的答案非常好。
标签: c# asp.net session webforms app-code