[英]Can I get the current executing controller from 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?
我可以从HttpContext获取它吗?
The class looks something like: 该类看起来像:
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;
}
Now I could manully inspect Request.RawUrl and parse and do funky things. 现在我可以手动检查Request.RawUrl并解析并做一些时髦的事情。 However, I don't want to write that kind and fall into trouble later when the application grows.
但是,我不想写那种,并在应用程序增长后遇到麻烦。 }
}
您可以在此对象中搜索"controller"
和"action"
的值
HttpContext.Request.RequestContext.RouteData.Values
不确定您正在执行的上下文,但您可以从RequestContext获取它:
RequestContext.RouteData.Values["controller"].ToString()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.