【发布时间】:2013-05-29 16:43:25
【问题描述】:
对不起,这个基本问题。
从Global.asax 中,我想获得控制器操作的绝对路径,就像我们从任何地方调用Response.Redirect("~/subfolder") 或从我们的视图中调用@Url.Content("~/controller/action") 一样。
在我的 Global.asax 活动中,我想做这样的事情:
protected void Application_BeginRequest(object sender, EventArgs args)
{
if ( string.Compare(HttpContext.Current.Request.RawUrl, "~/foo", true) == 0 )
// do something
// I'd like the "~foo" to resolve to the virtual path relative to
// the application root
}
【问题讨论】:
-
是否要比较 global.asax 中当前请求的控制器或操作名称?
-
是的。我不知道如何从
Global.asax中到达RouteData,或者我可以使用RouteData.GetRequiredString("controller")。
标签: asp.net asp.net-mvc