如何从wcf请求拦截器获取Authorization标头

时间:2011-09-25 23:42:05

标签: wcf

我需要验证对wcf服务的每个请求


 public class AuthenticationInterceptor : RequestInterceptor
    {
        public AuthenticationInterceptor() : base(false)
        {
        }

        public override void ProcessRequest(ref System.ServiceModel.Channels.RequestContext requestContext)
        {
          //How to access Request Header (Authorization header) from here?
        }
    }

1 个答案:

答案 0 :(得分:8)

您可以从System.ServiceModel.Channels.Message获取标题,请尝试

var message = requestContext.RequestMessage;
var request = (HttpRequestMessageProperty)message.Properties[HttpRequestMessageProperty.Name];

string authorization = request.Headers[HttpRequestHeader.Authorization];
相关问题