asp.net – 从Global.asax中获取操作的绝对URL路径
发布时间:2020-12-16 06:49:05 所属栏目:asp.Net 来源:网络整理
导读:对不起基本问题. 从Global.asax中,我想获得控制器动作的绝对路径,就像我们从任何地方调用Response.Redirect(“?/ subfolder”)或通过调用@ Url.Content(“?/ controller / action” “)来自我们的观点. 在我的Global.asax事件中,我想做这样的事情: protecte
对不起基本问题.
从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 } 解决方法
这是
answer for your problem
你可以简单地获得这样的控制器和动作名称 protected void Application_BeginRequest(object sender,EventArgs args) { HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current); UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); RouteData routeData = urlHelper.RouteCollection.GetRouteData(currentContext); string action = routeData.Values["action"] as string; string controller = routeData.Values["controller"] as string; if (string.Compare(controller,"foo",true) == 0) // do something // if the controller for current request if foo } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 浏览器关闭后的身份验证/会话cookie删除
- asp.net-web-api – 密码更改时如何使OAuth令牌无效?
- .NET Core容器化@Docker
- asp.net-mvc – 在asp.net mvc中将文本框类型转换为密码
- asp.net-mvc – 如何编辑MVC4表单中的子对象?
- asp.net-mvc – 使用Razor视图引擎 – 如何格式化十进制值以
- 动手造轮子:实现一个简单的 AOP 框架
- 如何为asp.net身份创建安全邮戳值(IUserSecurityStampStore
- asp.net-mvc – 在位于子域上的图像之间切换http和https
- 将ASP.NET与ASP混合使用
推荐文章
站长推荐
- asp.net-mvc – Ninject.Web.Common抛出Activati
- asp.net-mvc – Asp.net MVC 4 WEB API – 自定义
- asp.net-mvc – 具有WebApi和Controller路由的Ur
- asp.net – linq foreach表现
- asp.net-mvc – 使用浏览器栏将列表传递给MVC We
- asp.net – 如何在经典的asp中使用.net共享会话?
- asp.net-mvc – 如果ModelState表示该字段无效,则
- 在按钮ASP.NET c#上禁用回发
- asp.net – 请求格式无法识别的URL意外结束在’/
- Windbg程序调试系列4-Live Debugging
热点阅读