11
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using InCubatize.Helpers;

namespace InCubatize
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            //1
            ////Create and instance of TokenInspector setting the default inner handler
            //TokenInspector tokenInspector = new TokenInspector() { InnerHandler = new HttpControllerDispatcher(config) };

            ////Just exclude the users controllers from need to provide valid token, so they could authenticate
            //config.Routes.MapHttpRoute(
            //    name: "Authentication",
            //    routeTemplate: "api/users/{id}",
            //    defaults: new { controller = "users" }
            //);

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


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

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

            config.Routes.MapHttpRoute(name: "DefaultApiWithActionAndFiveParams",
                                    routeTemplate: "api/{controller}/{action}/{id1}/{id2}/{id3}/{id4}/{id5}/{id6}",
                                    defaults: new { id = RouteParameter.Optional });

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

            config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api



            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling =
                Newtonsoft.Json.PreserveReferencesHandling.None;

            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.EnableSystemDiagnosticsTracing();
        }
    }
}

Getting the below Error:-

'System.Web.Http.HttpConfiguration' does not contain a definition for 'EnableQuerySupport' and no extension method 'EnableQuerySupport' accepting a first argument of type 'System.Web.Http.HttpConfiguration' could be found (are you missing a using directive or an assembly reference?)

Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43
user3705566
  • 111
  • 1
  • 2
  • 10

3 Answers3

10

In Visual Studio go to "Tools" and then "Nuget Package Manager" and then "Package Manager Console"

Run the below command and it will fix the issue. Have tested it.

update-package microsoft.aspnet.webapi -reinstall

Navish Rampal
  • 482
  • 1
  • 5
  • 9
2

Note: This API is now obsolete.

https://msdn.microsoft.com/de-de/library/jj918506(v=vs.118).aspx

Rookian
  • 19,841
  • 28
  • 110
  • 180
  • use this instead: https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnet.odata.extensions.httpconfigurationextensions.addodataqueryfilter?view=odata-aspnet-7.0 – ozz Sep 17 '20 at 10:53
0

Check System.Web.Http.OData.dll - this is where this method is coming from, according to MSDN

Alex Buyny
  • 3,047
  • 19
  • 25
  • 1
    Ok Now it has gone. Thank you. But i am getting the similar error for "EnableSystemDiagnosticsTracing" please let me know what could be the issue. – user3705566 Oct 08 '14 at 02:35
  • Note that this method is now obsolete. https://msdn.microsoft.com/en-us/library/system.web.http.odata.enablequeryattribute(v=vs.118).aspx – Hugo Nava Kopp Mar 13 '17 at 11:14