【发布时间】:2018-04-18 12:08:04
【问题描述】:
我有一个获取路由属性的控制器:
[Route("api/v1/Admin/Keys")]
public class AdminController : Controller
{}
我的 Webproject 有以下路线:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Admin}/{action=GetAllKeys}/{id?}");
});
错误:
找不到此本地主机页面 没有找到该网络的网页 地址:http://localhost:60907/
当尝试调用控制器上的方法时,该方法也被路由,我一直得到相同的结果。
如果我从控制器中删除路由属性,那么这将开始工作,但我没有得到所需的路由。
我做错了什么?
编辑:
我在浏览器中调用的方法:
[HttpGet]
[Route("GetAllKeys")]
public async Task<IActionResult> GetAllKeys()
{
var data = await _manager.GetAllKeyTypes();
return Ok(data);
}
错误:
找不到此本地主机页面 没有找到该网络的网页 地址:http://localhost:60907/
EDIT2:
现在删除全局路由并仅使用:
[HttpGet("GetAllKeys")]
并使用以下网址: http://localhost:60907/GetAllKeys
这行得通,但又不受欢迎
【问题讨论】:
标签: c# api asp.net-core request