2.0: Global.asax simple problem

R

R.A.M.

Hello,
Could you help me please with a problem of Global.asax
implementation? I have little experience.

I have written Global.asax for my ASP.NET application:

<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["Users"] = 0;
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
Application["Users"] = 0;
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Response.Redirect("Error.html");
}
void Session_Start(object sender, EventArgs e)
{
Application.Lock();
Application["Users"] = (int)Application["Users"] + 1;
Application.Unlock();
}
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.
Application.Lock();
Application["Users"] = (int)Application["Users"] - 1;
Application.Unlock();
}
</script>

....But it does not work the way I expected because:
Problem 1: Session_End() is not called,
Problem 2: opening my application in a new browser window does not
call Session_Start(), so users counter is not increased.

Here is my Web.Config:
<?xml version="1.0"?>
....
<configuration>
<appSettings/>
....
<system.web>
<compilation debug="true"/>
<authentication mode="Forms">
<forms name="Demo.NET" loginUrl="Default.aspx" />
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
<customErrors mode="RemoteOnly" defaultRedirect="Error.html">
</customErrors>
<sessionState mode="InProc"
cookieless="false"
timeout="20"/>
</system.web>
</configuration>

Could you help me to solve problems 1st and 2nd?
Thank you very much!
/RAM/
 
D

dotnetjose

I only have a suggestion for Problem 2. If you already have an
instance of IE open and you pres ctrl+n or "file > new > window" to
create a new window does not start a new session if the default IE
settings are used.

First of all, the only way to start a new session accross multiple IE
windows is by changing a setting and using the task bar IE shortcut
instead of using ctrl+n.

What you have to do is go to Tools > Internet Options > "Advanced" tab
and uncheck the "Reuse windows for launching shortcuts". This will
make sure that everytime you launch a new instance of IE, through the
shortcut in the taskbar or programs menu, that a new IEXPLORER.exe
instance is launched.

If i remember correctly, sessions are only persitant to the instance of
IEXPLORER.exe that it was created on.

Hope that helps.

Jose
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top