如何从HttpAuthenticationContext获取自定义标头值

时间:2014-03-06 07:01:03

标签: asp.net-mvc http asp.net-web-api httpcontext

我正忙着实施和验证过滤器:

public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
    {
        var request = context.Request;

        // Receive token from the client. Here is the example when token is in header:
        var token = request.Headers.FirstOrDefault(x => x.Key == "Token").Value.ToString();   //["Token"];

如何获取名为token的标头?因为上面的代码不起作用。我猜这是因为它不是标准的标题。

2 个答案:

答案 0 :(得分:3)

request.Headers.GetValues("token");

答案 1 :(得分:0)

你应该实际使用

request.Headers.Authorization.Parameter;