Я внедрил пользовательский контекст NHibernate (ICurrentSessionContext). В этом контексте я добавляю сеанс NHibernate, поэтому у меня есть настройка сеанса для каждого шаблона вызова. Хорошо, теперь я сделал перехватчик, который принимает userId текущего зарегистрированного пользователя. Теперь я делаю это:Как получить аутентифицированный идентификатор пользователя из wcf в nhibernate
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 принимает UserId, но я не знаю, как (откуда), чтобы получить эту USERID.