我创建了一个ASP.NET-WebApi应用程序,我遇到了这个错误:
无法找到类型或命名空间名称HostAuthenticationFilter ...
代码是自动生成的,我认为它必须是参考,但无法找到该参考。
using System.Web.Http;
using Microsoft.Owin.Security.OAuth;
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
答案 0 :(得分:7)
您是否安装了Nugget软件包Microsoft ASP.NET Web API 2.2 OWIN:
https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Owin/