asp.net-mvc - 如何从 ASP MVC5 中的属性路由中获取路由名称

标签 asp.net-mvc routes asp.net-mvc-5 attributerouting

有谁知道如何从 Action 过滤器中的属性路由中获取路由名称?

例如,我有一个这样的 Controller 和属性路由:

[HttpGet]
[CustomActionAttribute]
[Route("~/index", Name="IndexPage")]
public async Task<ActionResult> Index()
{
    //Controller logic
}

是否可以在 CustomActionAttribute 中获取路由名称?
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    //Get the current route name here
}

最佳答案

您可以扩展 RouteCollection 来实现这一点。您可以找到此 here 的示例代码

关于asp.net-mvc - 如何从 ASP MVC5 中的属性路由中获取路由名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26284947/

相关文章:

c# - 覆盖登录页面上的防伪 token 错误

c# - Razor 引用未在 MVC 5 View 中解析 Visual Studio 2015 Enterprise

c# - Razor View IsAuthenticated 未按预期工作

ruby-on-rails - 将记录与显示操作中的嵌套路由相匹配

ruby-on-rails - Rails 4 - 如何匹配命名空间中的路由

Asp.Net MVC 5没有添加新 Controller ?

javascript - 为什么加载一些css和js文件需要很长时间?

asp.net-mvc - 部分 View 中的 ASP.NET MVC 自定义类型列表

asp.net-mvc - 将 iPad 设备的 MVC 设置为使用常规 Web 版本,而不是 .mobile

ruby-on-rails - Rails 可以理解 GET 请求,但不能理解 POST 请求