why not just inherits your all pages from this BaseForm ?
Because I have some template master pages for authorized and non authorized people.
I sorted it out with checking the session value on Page_Load event of master pages if session is expired then
the session value is null in this case we can talk about a session expiration.
And redirect the page.
This might be a quick and dirty way but it works for me.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["UserId"] == null)
Response.Redirect(" /HomePage.aspx");
}
}
It is sad that I can not do the same thing in Session_End event in global.asax.
Anyway, thanks
If there is an easy way of doing in Session_End event I'd love to hear that.
Regards
Yusuf
Session
Marked as answer by yusufcelik on Jun 06, 2008 12:06 PM
GillouX is right. It is impossible to redirect to a page in the Session end event handler because of the character of the http protocol which asp.net can not override.
We can descripe the scenario as follow:
1.Your broswer sends a http request to the web server for the fisst time.
2.The web server recieves the request, then starts a session and creates a session id. After processing the request, it sends back a http response(including the session id) to the broswer.
3. The broswer receives the response and gets the session id. Before the session is time out. The web server can identify the broswer by the session id(because the broswer will include the session id in the subsequent http resquests).
Note that the broswer and the web server have a active-passive relationship, that means if the broswer doesn't send a http request to the web server, the web server has no way to send a http response to the broswer because with just the session id,the web
server doesn't know where the broswer is.
4. When the session times out, the web server does something (the session end event handler) "internally". At this time, there is no http request and so no http response. The web server has no way notify the broswer of the session timeout.
Hope this can help you.
Session
What really matters most is the chance to communicate with you, rather than marking my post as answer, though I would be really appreciated if you do so.
yusufcelik
Member
27 Points
72 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 10:37 AM|LINK
As I understand I should inherit my all Pages from BaseForm
But, I am using MasterPages.
I can not use the same method for MasterPage right?
Regards
Yusuf
Session
GillouX
Contributor
2330 Points
606 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 11:44 AM|LINK
I don't know about using it with a Masterpage
why not just inherits your all pages from this BaseForm ?
yusufcelik
Member
27 Points
72 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 12:05 PM|LINK
Never mind.
Because I have some template master pages for authorized and non authorized people.
I sorted it out with checking the session value on Page_Load event of master pages if session is expired then
the session value is null in this case we can talk about a session expiration.
And redirect the page.
This might be a quick and dirty way but it works for me.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["UserId"] == null)
Response.Redirect(" /HomePage.aspx");
}
}
It is sad that I can not do the same thing in Session_End event in global.asax.
Anyway, thanks
If there is an easy way of doing in Session_End event I'd love to hear that.
Regards
Yusuf
Session
GillouX
Contributor
2330 Points
606 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 06, 2008 12:10 PM|LINK
like I said, there is no way to do it because it's just no possible according asp.net is made
My Crystal
Participant
1340 Points
353 Posts
Re: On Application.Session_End event cannot redirect to a page?
Jun 08, 2008 04:00 PM|LINK
GillouX is right. It is impossible to redirect to a page in the Session end event handler because of the character of the http protocol which asp.net can not override.
We can descripe the scenario as follow:
1.Your broswer sends a http request to the web server for the fisst time.
2.The web server recieves the request, then starts a session and creates a session id. After processing the request, it sends back a http response(including the session id) to the broswer.
3. The broswer receives the response and gets the session id. Before the session is time out. The web server can identify the broswer by the session id(because the broswer will include the session id in the subsequent http resquests).
Note that the broswer and the web server have a active-passive relationship, that means if the broswer doesn't send a http request to the web server, the web server has no way to send a http response to the broswer because with just the session id,the web server doesn't know where the broswer is.
4. When the session times out, the web server does something (the session end event handler) "internally". At this time, there is no http request and so no http response. The web server has no way notify the broswer of the session timeout.
Hope this can help you.
Session
ASP.NET 3.5 MCTS