0

Есть проект изначально чистый ASP.NET MVC, хочу внедрить в него функциональность Web API. Добавил следующие файлы в проект:

  • App_Start\WebApiConfig.cs

  • Providers\ApplicationOAuthProvider.cs

  • Controllers\ValuesController.cs

При запуске проекта возникают 3 ошибки:

CS1061 'HttpConfiguration' does not contain a definition for 'SuppressDefaultHostAuthentication' and no extension method 'SuppressDefaultHostAuthentication' accepting a first argument of type 'HttpConfiguration' could be found (are you missing a using directive or an assembly reference?) App_Start\WebApiConfig.cs


CS0246 The type or namespace name 'HostAuthenticationFilter' could not be found (are you missing a using directive or an assembly reference?) App_Start\WebApiConfig.cs


CS1061 'HttpConfiguration' does not contain a definition for 'MapHttpAttributeRoutes' and no extension method 'MapHttpAttributeRoutes' accepting a first argument of type 'HttpConfiguration' could be found (are you missing a using directive or an assembly reference?) App_Start\WebApiConfig.cs

Содержание App_Start\WebApiConfig.cs:

public static void Register(HttpConfiguration config)
{
    config.SuppressDefaultHostAuthentication();
    config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

    config.MapHttpAttributeRoutes();

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
}

Гугление ни к чему хорошему меня не привело(

1

1 ответ 1

1

Одних файлов недостаточно, вам нужно установить Web API нужной версии через NuGet также.

2
  • А можно поподробнее? Я все недостающие пакеты перенес в packages.config из стандартного проекта с Web API.
    – alfixed
    8 апр 2016 в 11:11
  • Нужно не переносить, а установить через NuGet. При установке прописываются настройки в XXX.config файлы и загружаются и устанавливаются соответствующие dll. (telerik.com/support/kb/data-access/details/…) 8 апр 2016 в 15:37

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.