473,563 Members | 2,897 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.IsNewS ession) - 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(ob ject sender, System.EventArg s e)
{
if (Session.IsNewS ession)
{
blnTimedOut = true; // fudge code
Response.Redire ct("~/sessionTimedOut .htm", false);
return;
}
this.MasterPage File = "~/master/" + Session["strSite"].ToString() +
".master";
}

protected void Page_Load(objec t sender, EventArgs e)
{
// this event fires even though Response.Redire ct 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 3529
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.IsNewS ession) - 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(ob ject sender, System.EventArg s e)
{
if (Session.IsNewS ession)
{
blnTimedOut = true; // fudge code
Response.Redire ct("~/sessionTimedOut .htm", false);
return;
}
this.MasterPage File = "~/master/" + Session["strSite"].ToString() +
".master";
}

protected void Page_Load(objec t sender, EventArgs e)
{
// this event fires even though Response.Redire ct 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*******@yaho o.nospammin.com wrote in message
news:6B******** *************** ***********@mic rosoft.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*******@yaho o.nospammin.com wrote in message
news:6B******** *************** ***********@mic rosoft.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*******@yaho o.nospammin.com wrote in message
news:C5******** *************** ***********@mic rosoft.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
1245
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
1268
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) which, when the browser is left untouched for an extended period of time, forward the user to a "session timed out" page of some sort. I assume...
1
16236
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 the global asa file. TIA
0
926
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
1241
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: loadSessionData(); // Populates a variable called sessionState if(sessionState.currentUser != null){
0
963
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 web.config file: <sessionState mode="InProc" cookieless="false" timeout="720"/> Does not work at all, session timeout after 20 minutes. I also tried to...
2
363
by: Fraijo | last post by:
how can i disable session timeouts without affecting any program codings?
3
1221
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 ... http://mysite.com?site=customer1
0
800
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 ASP.Net page, spending 30 minutes there working away, selecting data, then tries to get back to the ASP page. Meanwhile, the classic ASP page has...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.