我已经实现了NHibernate自定义上下文(ICurrentSessionContext)。 在这种情况下我注入NHibernate会话,所以我有Session每个调用模式设置。 好的,现在我做了一个截取当前登录用户的userId的拦截器。 现在我这样做:如何从nhibernate中的wcf获取经过身份验证的用户标识
public ISession CurrentSession()
{
// Get the WCF InstanceContext:
var contextManager = OperationContext.Current.InstanceContext.Extensions.Find<NHibernateContextManager>();
if (contextManager == null)
{
throw new InvalidOperationException(
@"There is no context manager available.
Check whether the NHibernateContextManager is added as InstanceContext extension.
Make sure the service is being created with the NhServiceHostFactory.
This Session Provider is intended only for WCF services.");
}
var session = contextManager.Session;
AuditLogInterceptor interceptor = new AuditLogInterceptor();
if (session == null)
{
session = this._factory.OpenSession(interceptor);
interceptor.Session = session;
contextManager.Session = session;
}
return contextManager.Session;
}
我AuditLogInterceptor需要用户ID,但我不知道如何(从那里)得到这个用户ID。