在参考了这篇文章后,我为基本 Http Authentication 编写了一个属性,用于 web api。在属性类中,如果提供的凭据匹配,那么我将 HttpContext.Current.User 设置为
HttpContext.Current.User = new GenericPrincipal(new ApiIdentity(apiUser), new string[] {});
base.OnActionExecuting(actionContext);
但是,当我在我的 api 控制器中访问 User 时,它没有 apiUser 属性。
为什么会这样,设置身份然后在 api 控制器中访问它的正确方法是什么?