Thursday, May 26, 2011

Find from which page the master file is invoked

Scenario

We may sometimes need to know from which page, the master file is invoked. Based on the file, we'll do some operation not for the other pages. For example if the user name in session is empty, it has to redirect to the login page otherwise the requested page should be opened. But at the same time, if the user request a login page, it should not redirect to the same page again.

Solution


In the above said scenario, we have to identify from where the master page is being called. We have the below code to identify from which page its called,

this.Parent.TemplateControl.AppRelativeVirtualPath.ToString() 


If you put this code in master page file, you will get to know the page from where it's invoked. Its taking the parents relativevirtualpath.


Happy Coding...



No comments:

Post a Comment