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 8874269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:40:35+00:00 2026-06-14T18:40:35+00:00

I am getting a recurring error occuring in the Session_Start method in the Global.asax.cs

  • 0

I am getting a recurring error occuring in the Session_Start method in the Global.asax.cs file (ASP.NET, C#, .NET Framework 4). The error seems to be happening on the following line

if (!OnlineVisitorsUtility.Visitors.ContainsKey(currentContext.Session.SessionID))

which basically checks to see if this sessionId is in the current list of SessionIds.

The error is

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at TestSystem.WebSite.Global.Session_Start(Object sender, EventArgs e) Global.asax.cs:line 142
at System.Web.SessionState.SessionStateModule.CompleteAcquireState()
at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

There is no user logged against the error (because this is thrown before anybody logs in). But no user has reported errors attempting to log in, the only reason we see this is because it is showing up in the error logs.

The error occurs every minute or so for a few days, then stops for a few days before re-surfacing.
We record the remote host ip for each error, and it is different for each instance of the error I have looked at. I initially thought it was some sort of automated job kicking this off, but when I track the location IP address I have found it originating in places we have users, places we don’t and a private (i’m guessing internal) IP address.

We cannot replicate this error on our internal test and QA systems. I am looking for help in two areas, first, anyone have any idea what could be causing this, and second, if not, what information could I log that would shed some light on what’s causing this?

Thanks,
Neil

EDIT

The dictionary in the error trace above is a dictionary that stores a SessionId and a WebsiteVisitor class.

public static Dictionary<string, WebsiteVisitor> Visitors = new Dictionary<string, WebsiteVisitor>();

We only add to this after checking the ContainsKey if statement above. The whole statement is below

lock (visitorsLock)
{
    if (!OnlineVisitorsUtility.Visitors.ContainsKey(currentContext.Session.SessionID))
    {
        OnlineVisitorsUtility.Visitors.Add(currentContext.Session.SessionID, new WebsiteVisitor(currentContext));
    }
}
  • 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-06-14T18:40:36+00:00Added an answer on June 14, 2026 at 6:40 pm

    Sounds like you have a synchronization problem with your Visitors dictionary. The Dictionary collection is not thread-safe so read/write access needs to be controlled. I see your using a locking object to resolve this issue, however, the problem with that approach is IIS doesn’t guarantee that each request will be running under the same AppDomain instance or even the same worker process.

    Instead of cross thread locking you need to look at cross process locking, I would suggest using a Mutex.

    Update

    Actually @RichardDeeming made a very good point – the Visitors object won’t be shared across multiple processes/AppDomain so it can’t be a synchronisation problem in that respect, however, the Dictionary is getting corrupt somehow. I would recommend switching to using a ConcurrentDictionary and let the framework take care of the synchronisation for you.

    Generally, static property in web apps aren’t a good idea as they can’t be shared across multiple AppDomains and you can end up running into mysterious issues like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a 302 error returning on a single CSS file on an ASP.NET
I am getting an error returning a linq query over http to an ASP.Net
Getting 401 errors when trying to use ASP.NET back end in load balanced environment
Getting the following thrown error when calling a web service. Have googled without any
I'm getting the following strange looking error. Unexpected PHP error [Use of undefined constant
I'm getting an error from a deterministic PG function that seems dependent based on
I'm getting the following error after I start debugging my program. Do you know
I'm getting the following errors in my erorr.log file on every request [Fri Jan
I'm getting this error message when try to compile the following void MyClass::MyFunc() const
Getting ERR_CONNECTION_RESET after more or less 2 minutes of uploading a rather big file

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.