我正在为我的Web API自定义基本身份验证。我想在每个请求的标头中发送特定的密钥,因此我从代码中删除了用户名和密码身份验证,并添加了自定义密钥,但是它不起作用。请看看它,我不知道我在做什么错。
COUNTIFS
当前我在
上收到public override void OnAuthorization(HttpActionContext actionContext)
{
IEnumerable<string> values;
if (actionContext.Request.Headers.TryGetValues("isValid", out values))
{
var authenticationToken = actionContext.Request.Headers.Authorization.Parameter;
var decodedAuthenticationToken = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationToken));
var SecretKey = decodedAuthenticationToken;
var isValid = SecretKey == "andydsfdsfdsfs";
if (isValid)
{
var principal = new GenericPrincipal(new GenericIdentity(SecretKey), null);
Thread.CurrentPrincipal = principal;
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, "User " + SecretKey + " successfully authenticated");
return;
}
}
HandleUnathorized(actionContext);
}
NullReferenceException