3

在我的服务中,有时会在错误处理程序中发生此异常:

system.servicemodel.security.securitynegotiationexception:服务器已拒绝客户端凭据。- 服务器已拒绝客户端凭据。- 登录尝试失败

不幸的是,我无法获得他们的参数,但我知道 EventLog 包含对所发生事件的更简短说明,包括用户名。

是否可以在错误处理程序中检索此信息?我的意思是,安全上下文未初始化,我无法获取它,但因此我需要通知用户某些事情已关闭。有样品:

    //this is std WCF interface implementation.
    internal sealed class ErrorHandler : IErrorHandler
    {
        public bool HandleError(Exception error)
        {
            var securityException = error as SecurityNegotiationException;
            if (securityException != null)
            {
                var invalidCred = securityException.InnerException as InvalidCredentialException;
                if (invalidCred != null)
                {
                    //there it is, I need username here.
                    log.Warn(invalidCred, "Invalid credentials. See event log.");
                    return true;
                }
            }
            return false;
        }
    }
4

0 回答 0