By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

Session timeouts and dynamic MasterPages

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.