【发布时间】:2009-12-11 21:43:21
【问题描述】:
我有一个 WCF 服务,我在其中使用 customUserNamePasswordValidatorType(在 web.config 文件的 behavior\serviceBehaviors\serviceCredentials\userNameAuthentication 部分中指定)。
我的自定义 UserNamePasswordValidator 就是这样工作的:
public bool Authenticate(string userName, string password)
{
If ( IsUserValid(username, password) )
{
UserInfo currentUser = CreateUserInfo(username);
//
// Here I'd like to store the currentUser object somewhere so that
// it can be used during the service method execution
//
return true;
}
return false;
}
在服务调用执行期间,我需要访问经过身份验证的用户的信息。例如我希望能够实现:
public class MyService : IService
{
public string Service1()
{
//
// Here I'd like to retrieve the currentUser object and use it
//
return "Hello" + currentUser.Name;
}
}
我的问题是在身份验证过程中我应该如何以及在哪里存储信息,以便在调用执行过程中可以访问它?只要“会话”有效,该存储就应该持续。
顺便说一句,我不使用(也不想使用)安全会话和/或可靠会话。所以我同时关闭了建立安全上下文和可靠会话。
我正在考虑启用 ASP.NET 兼容模式以将用户信息存储在 HttpContext.Current.Session 中,但我觉得不应该这样做。
【问题讨论】:
标签: wcf authentication