我可以从HttpContext获取当前执行的控制器吗? [英] Can I get the current executing controller from HttpContext?

查看:344
本文介绍了我可以从HttpContext获取当前执行的控制器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些3rd Party课程.我想在那获取我控制器的路由值.不幸的是,这并没有将当前正在执行的控制器交给我.我可以从HttpContext中获取它吗?

I am using some 3rd party classes. I want to get the routevalues of my controller in that. Unfortunately it doesn't hand me the current controller that is executing. Can I get it from HttpContext?

该类类似于:

public class ServiceStationVisibilityProvider
        : ISiteMapNodeVisibilityProvider 
    {

        public bool IsVisible(SiteMapNode node, HttpContext context, IDictionary<string, object> sourceMetadata)
        {
            node.Title = DateTime.Now.ToString(); //need to access routevalues and set title
            return true;
        }

现在,我可以手动检查Request.RawUrl并解析并做一些时髦的事情.但是,我不想编写这种代码,以后在应用程序扩展时遇到麻烦. }

Now I could manully inspect Request.RawUrl and parse and do funky things. However, I don't want to write that kind and fall into trouble later when the application grows. }

推荐答案

您可以在此对象中搜索"controller""action"的值

You can search the values of "controller" and "action" in this object

HttpContext.Request.RequestContext.RouteData.Values

这篇关于我可以从HttpContext获取当前执行的控制器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆