简体   繁体   中英

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.

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

might redirect to /Purchase.aspx?ID=5Type=2

of which I'd want the actual aspx file path.

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.

So how can I do it?

An asp.net Page treats a master page as just another control.

So if you want to get the page, you can always use the Page property provided by the MasterPage class.

我用这个工作了:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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