Asp.Net System.Web.Routing 查找实际的 .aspx 页面
我正在使用 System.Web.Routing 来获得一些更好的 URL,但遇到了问题。 我需要知道处理请求的实际页面。
例如,请求如下:
/basketball/home
我需要找到处理该请求的页面,例如:
/management/default.aspx
我只使用 System.Web.Routing 而不是 MVC。 我有一个包含一些路由信息的 RequestContext 句柄,但我没有看到我需要什么。
提前致谢。
******** 更新 ********
我能够使用 Context.CurrentHandler ,它给我 "ASP.management_default_aspx",而不是页面但足以获取页面名称。
I'm using System.Web.Routing to have some better URL's and have come across a problem. I need to know the actual page that's handling the request.
for example a request comes in as:
/basketball/home
I need to find the page that handles that request, like:
/management/default.aspx
I'm only using the System.Web.Routing and not MVC. I have a handle to the RequestContext that contains some of the route information, but i don't see what i need.
Thanks in advance.
******* UPDATE *******
I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
实际上还有另一种简单的方法来获取实际页面:
String vPath = ((System.Web.Routing.PageRouteHandler)Page.RouteData.RouteHandler).VirtualPath
不要忘记检查 Page.RouteData.RouteHandler 是否为 null - 当您直接获取没有 ASP.Net 路由的页面时。
There is actually another simple way to get the actual page:
String vPath = ((System.Web.Routing.PageRouteHandler)Page.RouteData.RouteHandler).VirtualPath
Do not forget to check Page.RouteData.RouteHandler is not null - while you are getting the page w/o ASP.Net routing but directly.
你不能从当前的 HttpContext 对象中检索它吗?
也许是这样的:
更新:
你尝试过这篇文章吗?
如何:从路由构造 URL
您应该能够从您构建的路由表中检索它。
Can you not retrieve this from the current HttpContext object?
Perhaps something like this:
UPDATE:
Have you tried this article?
How to: Construct a URL from a Route
You should be able to retrieve it back from the Routing table you have constructed.
vhinn bad 的答案有效...
您只需删除最初的波形符(“〜”),然后就可以开始了。
我不知道为什么它被否决了。 对我来说就像一个魅力。
vhinn terrible's answer worked...
You just have to remove the initial tilde ("~"), and you're ready to go.
I don't know why it was downvoted. Worked for me like a charm.
尝试使用此代码:
Try using this code:
我能够使用 Context.CurrentHandler 它给我“ASP.management_default_aspx”,不完全是页面,但足以获取页面名称。
I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.