Does a MasterPage know what page is being displayed?

前端 未结 12 1695
無奈伤痛
無奈伤痛 2021-01-02 11:53

When I navigate on a website utilizing MasterPages, does the application know what page I am on? If so, does it store it in an object I can access?

The reason I am

12条回答
  •  耶瑟儿~
    2021-01-02 12:14

    To get the current request URL from within the master page you would do:

    string s = this.Page.Request.FilePath; // "/Default.aspx"
    

    I also recommend moving your navigation into the master page instead of the content page. This will make it easier to maintain / access.

提交回复
热议问题