Search code examples
c#asp.net-web-apiroutesasp.net-web-api-routing

Getting error on Route attribute in Api method


I have created Api controller and trying to add 1 api method but getting error when adding Route attribute on my api method:

This is my method:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
 public class MyController : ApiController
    {
        [AllowAnonymous]
        [HttpPost]
        [Route("api/abc/Get")] //Getting error :type or namespace Route could not be found
        public async Task<object> Get()
        {
        }
    }

My dll references: enter image description here

But on Route Attribute i am getting error:

Error:Type or namespace Route could not be found


Solution

  • Probably you need to check if you have System.Web.Http assembly in your project references. if you used nuget please check if you have web api packages installed you can check it here:

    nuget package manager