小编Ras*_*dan的帖子

在WCF中提供Fault方法接收FaultException而没有详细信息

我已经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.";
    }
}
Run Code Online (Sandbox Code Playgroud)

我想知道是否有任何方法可以为错误及其状态代码编写更好的检查,或者如何获得授权异常而不是FaultException女巫更普遍?我发现在FailedAuthentication字符串后检查并不好,事实上它的授权不是认证...

c# service wcf exception microservices

7
推荐指数
1
解决办法
137
查看次数

标签 统计

c# ×1

exception ×1

microservices ×1

service ×1

wcf ×1