我已經實現了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。