I\'m writing code on the master page, and I need to know which child (content) page is being displayed. How can I do this programmatically?
This sounds like a bad idea to start with. The idea of the master is that it shouldn't care what page is there as this is all common code for each page.
I use this:
string pageName = this.ContentPlaceHolder1.Page.GetType().FullName;
It retuns the class name in this format "ASP.default_aspx", but I find that easy to parse for most purposes.
Hope that helps!
Page.Request.Url.PathAndQuery or one of the other properties of the Url Uri object should be available to you from the master page code.
I do something similar to this in a project of mine to dynamically attach css files based on the page being loaded. I just get the name of the file from the request:
this.Request.Url.AbsolutePath
And then extract the file name from there. I'm not sure if this will work if you are doing URL re-writes though.