473,505 Members | 14,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session timeouts and dynamic MasterPages

Hi,

I have a site which uses dynamic MasterPages. The selection of the
MasterPage to use is determined by an encrypted QueryString. Session_Start
looks for the presence of the QueryString, decrypts it, and sets up a
Session variable holding the name of the MasterPage to use. The contents
pages interrogate this Session variable in the Page_PreInit method (has to
be done here) and apply the correct MasterPage accordingly.

Works perfectly, until / unless the session times out. I'm checking for this
at the top of the Page_PreInit method using if (Session.IsNewSession) - this
works. If the IsNewSession is true, then the code redirects to a generic
page informing the user that they have been idle too long, and that they
must log in again. Fairly standard stuff.

HOWEVER, the problem I have is that the contents page then continues to load
i.e. its Page_Load fires, even though I've redirected to a different page.
I've worked round this by use of a boolean variable, as follows:

The code is as below:

bool blnTimedOut = false; // fudge variable

private void Page_PreInit(object sender, System.EventArgs e)
{
if (Session.IsNewSession)
{
blnTimedOut = true; // fudge code
Response.Redirect("~/sessionTimedOut.htm", false);
return;
}
this.MasterPageFile = "~/master/" + Session["strSite"].ToString() +
".master";
}

protected void Page_Load(object sender, EventArgs e)
{
// this event fires even though Response.Redirect in Page_PreInit
if (blnTimedOut ) // fudge code
{
return;
}
// rest of Page_Load code
}
Whilst the above most certainly works, I'm wondering if there is a better /
neater / more efficient way of doing this. E.g. is there a property of the
Page object that I can set in Page_PreInit to tell it not to fire any
further Page events...? I've done a trawl through MSDN and Google but have
drawn a blank...

Any assistance gratefully received.

Mark
Aug 5 '06 #1
4 3522
Mark,
Don't think so. I say, If it ain't broke, don't fix it!
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mark Rae" wrote:
Hi,

I have a site which uses dynamic MasterPages. The selection of the
MasterPage to use is determined by an encrypted QueryString. Session_Start
looks for the presence of the QueryString, decrypts it, and sets up a
Session variable holding the name of the MasterPage to use. The contents
pages interrogate this Session variable in the Page_PreInit method (has to
be done here) and apply the correct MasterPage accordingly.

Works perfectly, until / unless the session times out. I'm checking for this
at the top of the Page_PreInit method using if (Session.IsNewSession) - this
works. If the IsNewSession is true, then the code redirects to a generic
page informing the user that they have been idle too long, and that they
must log in again. Fairly standard stuff.

HOWEVER, the problem I have is that the contents page then continues to load
i.e. its Page_Load fires, even though I've redirected to a different page.
I've worked round this by use of a boolean variable, as follows:

The code is as below:

bool blnTimedOut = false; // fudge variable

private void Page_PreInit(object sender, System.EventArgs e)
{
if (Session.IsNewSession)
{
blnTimedOut = true; // fudge code
Response.Redirect("~/sessionTimedOut.htm", false);
return;
}
this.MasterPageFile = "~/master/" + Session["strSite"].ToString() +
".master";
}

protected void Page_Load(object sender, EventArgs e)
{
// this event fires even though Response.Redirect in Page_PreInit
if (blnTimedOut ) // fudge code
{
return;
}
// rest of Page_Load code
}
Whilst the above most certainly works, I'm wondering if there is a better /
neater / more efficient way of doing this. E.g. is there a property of the
Page object that I can set in Page_PreInit to tell it not to fire any
further Page events...? I've done a trawl through MSDN and Google but have
drawn a blank...

Any assistance gratefully received.

Mark
Aug 6 '06 #2
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:6B**********************************@microsof t.com...
Don't think so.
OK.
I say, If it ain't broke, don't fix it!
Well, yeah, but I'm always interested in finding better ways of doing
things...

Maybe there are none in this particular case... There certainly seems to be
no way of one of the "early" Page methods telling the "later" ones not to
fire... This can get annoying if the creation of the page needs to be
aborted in the Page_PreInit, and you subsquently have Page_Init, Page_Load,
Page_PreRender and Page_Unload... :-)

Nil desperandum - it works...
Aug 6 '06 #3
Hmmm.
I suppose you *could* do that, e.g. have a boolean somewhere and the "early"
lifecycle method / event can set this, and your code in the later one would
check for it and only execute certain code if it's true, no?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mark Rae" wrote:
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:6B**********************************@microsof t.com...
Don't think so.

OK.
I say, If it ain't broke, don't fix it!

Well, yeah, but I'm always interested in finding better ways of doing
things...

Maybe there are none in this particular case... There certainly seems to be
no way of one of the "early" Page methods telling the "later" ones not to
fire... This can get annoying if the creation of the page needs to be
aborted in the Page_PreInit, and you subsquently have Page_Init, Page_Load,
Page_PreRender and Page_Unload... :-)

Nil desperandum - it works...
Aug 6 '06 #4
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:C5**********************************@microsof t.com...
I suppose you *could* do that, e.g. have a boolean somewhere and the
"early"
lifecycle method / event can set this, and your code in the later one
would
check for it and only execute certain code if it's true, no?
Er, did you actually *read* the code in my original post...?

That is *precisely* what I'm doing... ;-)
Aug 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1243
by: Dave | last post by:
What are some of the draw backs about setting a very long session time out? What is 'too long' ?
1
1263
by: David P. Donahue | last post by:
What is the best way (or what ways have been successful for you) to notify a user on a website that their session has timed out? I've seen various sites around the internet (my bank, for example)...
1
16230
by: Poppy | last post by:
Is it possible for me to increase the time before a session times out and do it in the global or webconfig files ? In asp I used to put session.timeout = whatever in the session start event of...
0
924
by: Jason | last post by:
What is the best way to set these timeouts? Should both be the same and what will happen if they are different? Thanks Jason
6
1235
by: Simon Harvey | last post by:
Hi everyone, If anyone can help me with the following I would be very greatful. In order to determine when a session has timed out I have some code in each page that does something like: ...
0
959
by: Ed Chiu | last post by:
Hi, I have an ASP.Net application, actually it's a modification of ASP.Net Portal starter kit. I am trying to change session timeout to go beyond 20 minutes. I have the following in the...
2
363
by: Fraijo | last post by:
how can i disable session timeouts without affecting any program codings?
3
1218
by: M O J O | last post by:
(using asp.net 2.0) Hi, I have 5-6 large customers each using the same pages, but with their own themes. To enter my site, they all have their own urls like ... ...
0
796
by: davidanoble | last post by:
We are converting our classic ASP application to ASP.Net, albeit slowly and have come across a problem. A user navigates through the existing application (classic ASP). Then navigates to the new...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.