Please help as this issue is driving us crazy...
Any idea would be of great help..
Application is running over IIS and I am getting error "
Index was outside the bounds of the array." on the Session_Start on line
When I tried to catch the error I got random values for AllSessions.Cou nt. It touched 77 and after a day it came back on 66 and in an hour it touched 99.
Now, my question is why I am getting error even after removing session from Dictionary object under Session_End event.
Here is my global.asax file
here is my GetSession class
Any idea would be of great help..
Application is running over IIS and I am getting error "
Index was outside the bounds of the array." on the Session_Start on line
Code:
AllSessions[Session.SessionID] = GetSession.GetNewSession(Context);
When I tried to catch the error I got random values for AllSessions.Cou nt. It touched 77 and after a day it came back on 66 and in an hour it touched 99.
Now, my question is why I am getting error even after removing session from Dictionary object under Session_End event.
Here is my global.asax file
Code:
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
private static Dictionary<String, GetSession> AllSessions = new Dictionary<String, GetSession>();
void Application_Start(object sender, EventArgs e)
{
Context.Cache.Insert("Web.AllSessions", AllSessions);
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
try
{
AllSessions[Session.SessionID] = GetSession.GetNewSession(Context);
// Code that runs when a new session is started
}
catch (Exception ex)
{
Web.Globals.WriteError("SessionInCache.GetNewSessionForCache(Context) -> " + ex.Message + "REMOTE_HOST: " + Context.Request.ServerVariables["REMOTE_HOST"] + " SessionID " + Context.Session.SessionID + " Number of sessions " + AllSessions.Count);
}
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
AllSessions.Remove(Session.SessionID);
}
</script>
Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for GetSession
/// </summary>
public class GetSession
{
private String m_SessionId = null;
public String m_UserAgent = null;
public String m_RemoteHost = null;
public String m_RemoteAddr = null;
public String m_AcceptCharsets = null;
public String m_AcceptEncodings = null;
public String m_AcceptLanguage = null;
public String m_EmplId = null;
public String m_LoginName = null;
public DateTime m_SessionStart = DateTime.UtcNow;
public GetSession()
{
//
// TODO: Add constructor logic here
//
}
public static GetSession GetNewSession(HttpContext Context)
{
GetSession mySession = null;
try
{
mySession = new GetSession();
mySession = new GetSession();
mySession.m_SessionId = Context.Session.SessionID;
mySession.m_UserAgent = Context.Request.ServerVariables["HTTP_USER_AGENT"];
mySession.m_RemoteHost = Context.Request.ServerVariables["REMOTE_HOST"];
// Handle HTTP proxy forwarding
if (Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) mySession.m_RemoteAddr = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
else if (Context.Request.ServerVariables["HTTP_FORWARDED"] != null) mySession.m_RemoteAddr = Context.Request.ServerVariables["HTTP_FORWARDED"];
else mySession.m_RemoteAddr = Context.Request.ServerVariables["REMOTE_ADDR"];
mySession.m_AcceptCharsets = Context.Request.ServerVariables["HTTP_ACCEPT_CHARSET"];
mySession.m_AcceptEncodings = Context.Request.ServerVariables["HTTP_ACCEPT_ENCODING"];
mySession.m_AcceptLanguage = Context.Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
return mySession;
}
}
Comment