加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 03:16:36 所属栏目:asp.Net 来源:网络整理
导读:有谁知道如何从动作过滤器中的属性路由获取路由名称? 例如,我有一个控制器和属性路由,如下所示: [HttpGet][CustomActionAttribute][Route("~/index",Name="IndexPage")]public async TaskActionResult Index(){ //Controller logic} 是否可以在CustomActio
有谁知道如何从动作过滤器中的属性路由获取路由名称?

例如,我有一个控制器和属性路由,如下所示:

[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的示例代码

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读