Q: ASP.NET Is it possible to handle all the null session checking in masterpage I have the following steps in my webpage
1) User Logs in and I set the following session variables
     Session("userName") = reader_login("useremail").ToString()
     Session("userId") = reader_login("user_ID").ToString()
     Session("firstName") = reader_login("firstName").ToString()

2) Now on my logged in VB.NET templates I reference a MasterPage called LoggedIn.Master. In Which I added the following method to check for the above null session variables. And if they null to redirect back to login page.
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

    '#Check that User is Logged in, if not redirect to login page
    If (Session("userId") Is Nothing) Or (Session("userName") Is Nothing) Or (Session("firstName") Is Nothing) Then
        Response.Redirect(ConfigurationManager.AppSettings("site_base_url").ToString & "login/", False)
    End If

3) Now my question is if I want to use any above 3 Session variables in different .net templates or usercontrols referencing the above master page  do i need to AGAIN add the check
        If (Session("userId") Is Nothing) Or (Session("userName") Is Nothing) Or (Session("firstName") Is Nothing) Then
        Response.Redirect(ConfigurationManager.AppSettings("site_base_url").ToString & "login/", False)
    End If

In the respective pages or will the check in master page do. Because at the moment i.e. if in a usercontrol I attempt to do i.e.
customerName.Text = Session("userName").ToString()

or
Response.Write(Session("userName").ToString())

I am getting the error
Object reference not set to an instance of an object.
customerName.Text = Session("userName").ToString()

A: You can write a wrapper around the Session to handle null values and just call the wrapper when you access the items:
Public Class SessionWrapper
   Public Shared ReadOnly Property Item()
     'Access session here and check for nothing
   End Property
End Class

And use it like this
SessionWrapper.Item("itemName")


A: You can create an http module that asks about the session objects and if they are null, it will redirect to the login page and by developing this http module, in each page request the module will do the check and then you can use it normally without checking.

A: In answer to your question - as long as the masterpage checks the session and redirects before all your controls and page code make a reference to Session, you should be fine. 
You were using OnInit() which seems reasonable, but see this article for a good understanding of the timing of events.
Incidentally, I strongly discourage the use of ad-hoc calls to Session in your page and control code. Instead, I recommend you create a static SessionManager class that does the Session referencing for you. That way, you get to benefit from strong typing, and won't be able to accidentally make hard-to-debug 'session key' typos in your code like Session["FiirstName"]. Also, you can incorporate your null-session check right into the call for the session value:
EXAMPLE (in C#, sorry!)
public static class SessionManager
{
    private static void EnsureUserId()
    {
        if (Session["userId"] == null)
        {
            Response.Redirect("YourLogin.aspx", false);
        }
    }

    public static string FirstName
    {
        get 
        {
             EnsureUserId();
             if (Session["firstName"] == null) 
                 Session["firstName"] = ""; 
             return (string)Session["firstName"]; 
        }
        set
        { 
             Session["firstName"] = value;
        }
    }

}


A: A better way to handle this would be to add a base class for all controls that require this session variables to be present. You can then add properties to wrap access to the session and other cool stuff and the check will work even if the controls are used with a different master page.
