3

I'm somewhat new to ASP / C# and I'm having an issue (probably simple) with sessions variables.

My project has Master pages and web forms in which session variables are checked under the Page_Load method like so:

    if (!(Session["matricula"] != null))
    {
        Response.Redirect("default.aspx");
    }

This does work. So, my problem lies when I try to apply other methods that access those session variables. I'm running across lots of cases where I use session variables for methods, but I get the

"Object reference not set to an instance of an object"

...errors when timeout occurs.

How can I deal with all of the session variables, in order to redirect the user to the login page when timeout occurs? is there another way instead of adding the same method (given above) everywhere?

DavidM
  • 307
  • 2
  • 6
  • 22

0 Answers0