简体   繁体   English

通过路由从母版页获取当前页面URL

[英]Getting Current Page URL From Master Page with Routing

I'm trying to be able to determine which page url the user is loading from the master page. 我试图确定用户从母版页加载的页面URL。

So far I've been able to use 到目前为止,我已经可以使用

this.Request.RawUrl

to get the path of the page itself, which works fine for most cases. 获取页面本身的路径,在大多数情况下都可以正常工作。

However in this particular website, we use a lot of complicated routing, so something like (say) 但是,在这个特定的网站中,我们使用了许多复杂的路由,因此(例如)

/Product/5/2/Purchase /产品/ 5/2 /购买

might redirect to /Purchase.aspx?ID=5Type=2 可能会重定向到/Purchase.aspx?ID=5Type=2

of which I'd want the actual aspx file path. 我想要实际的aspx文件路径。

I've also tried this.Request.PhysicalPath , but that doesn't give the route and basically just appends the path the user requested to the virtual directory. 我也尝试过this.Request.PhysicalPath ,但这并没有给出路由,基本上只是将用户请求的路径附加到虚拟目录中。

So how can I do it? 那我该怎么办呢?

An asp.net Page treats a master page as just another control. asp.net页将母版页视为另一个控件。

So if you want to get the page, you can always use the Page property provided by the MasterPage class. 因此,如果要获取页面,可以始终使用MasterPage类提供的Page属性。

我用这个工作了:

Page.ToString().Replace("ASP.","").Replace("_",".")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM