I am using Gloabl.asax to watch how many users are online and when the session expires move to another page.
When a session ends it fires up the Session_End event in Global.asax.
But, I cannot use neither Response.Redirect("~/Home.aspx"); nor FormsAuthentication.SignOut();
It raises an System.NullReferenceException.
can you post all the code of the global.asax page.
Sure no problem
<%@ Application Language="C#" %>
<script RunAt="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on the application startup
// Specify the connection string, which is used to open a database.
Application["UsersOnline"] = 0;
}
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
//System.Web.HttpApplication app = sender as HttpApplication;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
try
{
Application["UsersOnline"] = (int)Application["UsersOnline"] + 1;
}
finally
{
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();
try
{
Application["UsersOnline"] = (int)Application["UsersOnline"] - 1;
}
finally
{
Application.UnLock();
}
Server.Transfer("Default.aspx");//Resources.Resource.lnkAnaSayfa);
}
</script>
there is no way to use Server.Transfert or Response.redirect inside GLobal.asax because there is not HTTPreques associated , the session_end being called internally !
yusufcelik
Member
27 Points
72 Posts
On Application.Session_End event cannot redirect to a page?
Jun 05, 2008 02:06 PM|LINK
Hi,
I am using Gloabl.asax to watch how many users are online and when the session expires move to another page.
When a session ends it fires up the Session_End event in Global.asax.
But, I cannot use neither Response.Redirect("~/Home.aspx"); nor FormsAuthentication.SignOut();
It raises an System.NullReferenceException.
Any help is appreciated
Regards
Yusuf
Session
GillouX
Contributor
2330 Points
606 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 05, 2008 02:20 PM|LINK
yusufcelik
Member
27 Points
72 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 05, 2008 02:23 PM|LINK
How about why can not I use FormsAuthentication.SignOut() ?
Regards
Yusuf
Session
yusufcelik
Member
27 Points
72 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 05, 2008 02:28 PM|LINK
Sorry still got the same error
Session
GillouX
Contributor
2330 Points
606 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 05, 2008 02:48 PM|LINK
Maybe you should better use a Httpmodule for that
I found an example about handling the end of a session
http://www.codeproject.com/KB/aspnet/SessionEndStatePersister.aspx
yusufcelik
Member
27 Points
72 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 08:56 AM|LINK
Thanks,
But, I am using InProc session state.
No good for me.
Regards
Yusuf
Session
GillouX
Contributor
2330 Points
606 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 09:02 AM|LINK
can you post all the code of the global.asax page.
yusufcelik
Member
27 Points
72 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 09:12 AM|LINK
Sure no problem
<%@ Application Language="C#" %>
<script RunAt="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on the application startup
// Specify the connection string, which is used to open a database.
Application["UsersOnline"] = 0;
}
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
//System.Web.HttpApplication app = sender as HttpApplication;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
try
{
Application["UsersOnline"] = (int)Application["UsersOnline"] + 1;
}
finally
{
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();
try
{
Application["UsersOnline"] = (int)Application["UsersOnline"] - 1;
}
finally
{
Application.UnLock();
}
Server.Transfer("Default.aspx");//Resources.Resource.lnkAnaSayfa);
}
</script>
Session
GillouX
Contributor
2330 Points
606 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 09:20 AM|LINK
I found the information
there is no way to use Server.Transfert or Response.redirect inside GLobal.asax because there is not HTTPreques associated , the session_end being called internally !
GillouX
Contributor
2330 Points
606 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 09:21 AM|LINK
I found this article which provides a solution which seems to work
http://dotnet.org.za/thea/archive/2004/07/27/3022.aspx