简体   繁体   English

在Api方法中获取Route属性错误

[英]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: 我创建了Api控制器并尝试添加1种api方法,但是在我的api方法上添加Route属性时出现错误:

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: 我的dll参考: 在此处输入图片说明

But on Route Attribute i am getting error: 但是关于路线属性我得到错误:

Error :Type or namespace Route could not be found 错误 :找不到类型或名称空间路由

Probably you need to check if you have System.Web.Http assembly in your project references. 可能需要检查项目引用中是否有System.Web.Http程序集。 if you used nuget please check if you have web api packages installed you can check it here: 如果您使用nuget,请检查是否已安装Web api软件包,您可以在此处进行检查:

nuget包管理器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM