作者:华女-1_572 | 来源:互联网 | 2022-12-05 14:44
我已经IErrorHandler
为我的服务实施了一个女巫需要返回403而不是400以防错误授权.
这是我的ProvideFault
方法的样子:
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (((FaultException)error).Code.SubCode.Name == "FailedAuthentication")
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription =
"StatusCode is forced to change in order to have the correct response on authentication.";
}
}
我想知道是否有任何方法可以为错误及其状态代码编写更好的检查,或者如何获得授权异常而不是FaultException
女巫更普遍?我发现在FailedAuthentication
字符串后检查并不好,事实上它的授权不是认证...