Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:09:18+00:00 2026-05-29T05:09:18+00:00

I have a class with a subroutine as follows: Public Sub SetPermissions() If IsNothing(HttpContext.Current.Session)

  • 0

I have a class with a subroutine as follows:

Public Sub SetPermissions()
    If IsNothing(HttpContext.Current.Session) Then
        Exit Sub
    Else
        Dim session As HttpSessionState = HttpContext.Current.Session
        If Not IsNothing(session("UserId")) Then '<-- exception occurs here
            'Do Stuff
        End If
    End If
End Sub

I know that my session variable is not yet set, hence a null value, that’s why i’m trying to handle it with IsNothing, but my code still bugs out on me.

Any ideas?
Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:09:19+00:00Added an answer on May 29, 2026 at 5:09 am

    If you are going to try to access Session variables from Global.asax, you need to make sure you use an event that is fired after Session has been initialized for the current request. If you take a look at the documentation on MSDN, you’ll see there are several events you can wire up in the Global.asax (check out the list of events in the section “The request is processed by the HttpApplication pipeline”).

    If you wire up those events, you should find that Session is initialized before Application_AcquireRequestState is raised. If you move your code out of Application_AuthenticateRequest and into Application_AcquireRequestState then it should work properly.

    Note that I used the following code to test when Session would be initialized (C#, sorry). I wired up each event in order from the documentation, and Application_AcquireRequestState was the first event where I saw session == null evaluate to false.

    void Application_AcquireRequestState(object sender, EventArgs e)
    {
        var session = HttpContext.Current.Session;
        Response.Write("Application_AcquireRequestState: -> session is null: ");
        Response.Write(session == null);
        Response.Write("<br />");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class A: public class ClassA<T> Class B derives from A: public class
I have class A: public B { ...} vector<A*> v; I want to do
I have class Fred { public: void inspect() const {}; void modify(){}; }; int
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
At the moment, I have the following code: Public tmr() As DispatcherTimer Public Sub
I have: class A {...}; class B : public A {...}; class C :
I have: class first{ private: int *array; public: first(int x){ array = new int[x][10];
I have the following subroutine in a classic ASP class that calls the ADO
In a base class object, I have an overridable subroutine that I would like
I have some code which is effectively this: class dummie_type { public: int a;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.