Note that there are some explanatory texts on larger screens.

plurals
  1. POpage_load event in Master and Content Pages
    text
    copied!<p>Here is the sequence in which events occur when a master page is merged with a content page:</p> <p><a href="http://msdn.microsoft.com/en-us/library/dct97kc3.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dct97kc3.aspx</a></p> <p>So, my problem is:</p> <p>I have one login page (not use master page), one master page, and hundreds of content page.</p> <p>I check login session <code>Session["loggedInUser"]</code> in master page (if not logged in, redirect to login page)</p> <p>So, when I don't log in, if I type the address of one content page, it must check login session in master page and redirect to login page, right? But it has two cases here:</p> <p>If in content page, I don't use anything related to <code>Session["loggedInUser"]</code>, it will redirect to login page, so, it's OK here!</p> <p>The second case: if I use <code>Session["loggedInUser"]</code> to display Username in content page for example:</p> <pre><code>UserInfo loggedInUser = (UserInfo)Session["loggedInUser"]; </code></pre> <p>it will return null object here, <strong>because the <code>page_load</code> in content page is fired before <code>page_load</code> in master page</strong>, so it thows null object instead of redirecting to login page.</p> <p>I also tried <code>Page_PreInit</code> in master page but no help</p> <pre><code>protected void Page_PreInit(object sender, EventArgs e) { if (Session["loggedInUser"] == null) { Response.Redirect("~/Login.aspx"); } } </code></pre> <p>Any suggestion?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload