我有一个调用 DLL 的 web 应用程序,这个 dll 从 web 服务中获取一些数据。我想做的是当用户登录到网络应用程序时,我目前将它的用户名存储在会话变量中。在我的 webService 中,我有一个这样的 WebMethod:
[WebMethod(EnableSession = true)]
public string getLoggedInUsername()
{
SessionManager session = new SessionManager();
return session.Username;
}
这工作正常,但是当我从 DLL 访问 web 服务时,返回的值始终为 NULL,这是因为当控制台应用程序连接到 web 服务时,将初始化一个新会话。有没有其他方法可以存储登录的用户名并通过我的网络服务将其传递给 dll?使用 Application Get/Set 不是一个好的决定,因为我的 webapp 需要处理不同的用户。任何人都可以指出我正确的方向吗?
SessionManager 类包含以下内容:
public string Username
{
get
{
return (string)HttpContext.Current.Session["Username"];
}
set
{
HttpContext.Current.Session["Username"] = value;
}
}
在用户登录到我的应用程序后(我正在使用 asp.net 成员资格):我以这种方式将用户名分配给会话变量:
SessionManager session = new SessionManager();
session.Username = User.Identity.Name;
谢谢。