Api 方法中的 Route 属性出错
Getting error on Route attribute in Api method
我已经创建了 Api 控制器并尝试添加 1 个 api 方法,但是在我的 api 方法上添加 Route 属性时出现错误:
这是我的方法:
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()
{
}
}
我的 dll 引用:
但是在 路线 属性上我收到错误:
错误:找不到类型或命名空间路由
可能您需要检查您的项目引用中是否有 System.Web.Http 程序集。如果你使用了 nuget,请检查你是否安装了 web api 包
你可以在这里查看:
我已经创建了 Api 控制器并尝试添加 1 个 api 方法,但是在我的 api 方法上添加 Route 属性时出现错误:
这是我的方法:
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()
{
}
}
我的 dll 引用:
但是在 路线 属性上我收到错误:
错误:找不到类型或命名空间路由
可能您需要检查您的项目引用中是否有 System.Web.Http 程序集。如果你使用了 nuget,请检查你是否安装了 web api 包 你可以在这里查看: