If you do all this in the Page_Init or Page_PreInit event on the page you should have all the information available to you, and it should still be early enough in the page life-cycle to make the type of changes I think you might want to make. If you create your own page base class, and then in web.config make all pages inherit that class you can write the code once and apply it to all pages.