c# - ASP.NET 5 中的 RoutePrefixAttribute

标签 c# asp.net-web-api2 asp.net-core dnx

我在 ASP.NET 5 中启动了一个新的 Web API 2.0 项目。我尝试创建自定义 RoutePrefixAttribute 类,但出现此错误

The type or namespace name 'RoutePrefixAttribute' could not be found 
(are you missing a using directive or an assembly reference?)   {ProjectName}.DNX Core 5.0

我应该改用其他类吗?

最佳答案

在 MVC 6 中确实没有 RoutePrefixAttribute。在 Controller 上应用 [Route] 属性现在将充当路由前缀:

[Route("api/[controller]/[action]")]
public class ProductsController : Controller
{
    [Route("{id:int}")]
    public JsonResult Details(int id)
    {
        // ...
    }
}

这将匹配 api/Products/Details/42

另见 this blogpost作者:Filip W。

关于c# - ASP.NET 5 中的 RoutePrefixAttribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31766427/

相关文章:

c# - 当按下 'Next' 按钮时如何继续显示 LINQ 结果?

c# - 在内存中创建 Zip 存档,并从 web api 返回它

c# - 覆盖 ModelState 非常技术性的错误消息

c# - Post 方法在 ASP.NET Core 中不起作用

asp.net-core - IIS 不会为 Net 6 提供服务,即使安装了 Hosting Bundle

c# - Web 应用程序之间的 Asp.Net Core DataProtection 无法在 Azure 上运行

c# - OnCollisionEnter2D 和 OnCollisionExit2D 的问题

c# - 在 silverlight 中刷新 DataGrid

c# - 如何知道 child 添加到 StackPanel?

Azure 应用服务 WebApp 正常关闭/重新启动