Hi,
You should not add any code to layout.master directly. You could create a UserControl and add it to layout.master and put your code in the UserControl.
All CMS pages, that is pages listed in the menu are served by Default.aspx?pageid=x but we use url rewriting to keep a friendly url in the browser bar. From code you can get the url generally with Request.RawUrl, but realize that the home page will be shown with any of 3 urls like http://yoursiteroot/ or http://yoursiteroot/Default.aspx or http://yoursiteroot/home.aspx
Hope it helps,
Joe