PC Review


Reply
Thread Tools Rate Thread

Check environment in application_start

 
 
MattB
Guest
Posts: n/a
 
      10th Jan 2008
I'm trying to put some code in my asp.net 1.1 application that checks
some dependencies. I want to alert the user if something is missing or a
component version is out of sync.
I've been able to do the checking logic, but can't do what I want from
the application_start event. What I fist intended to do was set a
session variable, Session("lasterror") and redirect to my internal error
page that would tell the user what happened.
But I can't seem to be able to set a session variable OR redirect from
this event ("...not available in this context."). So what do you people
do in situations like this? I had considered the session_start event but
that would fire too often and I'd be afraid of performance issues if a
site was busy.

Thanks,
Matt
 
Reply With Quote
 
 
 
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      10th Jan 2008
Correct. I know this sounds simplistic, but how about we save the info to a
text file from Application_Start and have the default page read and display
it? If your default page detects there's nothing in the file, it continues,
otherwise we can redirect to an error info page that displays the information
with instructions.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


"MattB" wrote:

> I'm trying to put some code in my asp.net 1.1 application that checks
> some dependencies. I want to alert the user if something is missing or a
> component version is out of sync.
> I've been able to do the checking logic, but can't do what I want from
> the application_start event. What I fist intended to do was set a
> session variable, Session("lasterror") and redirect to my internal error
> page that would tell the user what happened.
> But I can't seem to be able to set a session variable OR redirect from
> this event ("...not available in this context."). So what do you people
> do in situations like this? I had considered the session_start event but
> that would fire too often and I'd be afraid of performance issues if a
> site was busy.
>
> Thanks,
> Matt
>

 
Reply With Quote
 
MattB
Guest
Posts: n/a
 
      10th Jan 2008
Sometimes simplistic is best. Thanks for the idea!

Matt

Peter Bromberg [C# MVP] wrote:
> Correct. I know this sounds simplistic, but how about we save the info to a
> text file from Application_Start and have the default page read and display
> it? If your default page detects there's nothing in the file, it continues,
> otherwise we can redirect to an error info page that displays the information
> with instructions.
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "MattB" wrote:
>
>> I'm trying to put some code in my asp.net 1.1 application that checks
>> some dependencies. I want to alert the user if something is missing or a
>> component version is out of sync.
>> I've been able to do the checking logic, but can't do what I want from
>> the application_start event. What I fist intended to do was set a
>> session variable, Session("lasterror") and redirect to my internal error
>> page that would tell the user what happened.
>> But I can't seem to be able to set a session variable OR redirect from
>> this event ("...not available in this context."). So what do you people
>> do in situations like this? I had considered the session_start event but
>> that would fire too often and I'd be afraid of performance issues if a
>> site was busy.
>>
>> Thanks,
>> Matt
>>

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      10th Jan 2008
"MattB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I'm trying to put some code in my asp.net 1.1 application that checks some
> dependencies. I want to alert the user if something is missing or a
> component version is out of sync.
> I've been able to do the checking logic, but can't do what I want from the
> application_start event. What I fist intended to do was set a session
> variable, Session("lasterror") and redirect to my internal error page that
> would tell the user what happened.
> But I can't seem to be able to set a session variable OR redirect from
> this event ("...not available in this context.").


That's right - Application_OnStart occurs *before* the first session is
created i.e. before the Session_Start event fires for the user whose
accessing the site caused it to start up... This means that, although the
the Application and Server built-in objects are available within
Application_OnStart, very little else of that nature is... As you've
discovered, trying to reference the Session, Request, or Response objects in
Application_OnStart event causes an error....

> So what do you people do in situations like this?


In similar situations, I've set a flag in the app's backend database...

> I had considered the session_start event but that would fire too often and
> I'd be afraid of performance issues if a site was busy.


The Session_Start event would fire no more often than normal, since it fires
every time a new Session is created... If your app has to query the backend
database in Session_Start, this would seem a fairly suitable place to check
for your working environment...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      10th Jan 2008
"MattB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> Sometimes simplistic is best. Thanks for the idea!


How about...?

protected void Application_Start(Object sender, EventArgs e)
{
Application["OkToRun"] = <code to check viable environment>;
}

protected void Session_Start(Object sender, EventArgs e)
{
if ((bool)Application["OkToRun"])
{
Response.Redirect("homepage.aspx", false);
}
else
{
Response.Redirect("errorpage.aspx", false);
}
}


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
MattB
Guest
Posts: n/a
 
      11th Jan 2008
Perfect. Thanks!

Matt

Mark Rae [MVP] wrote:
> "MattB" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Sometimes simplistic is best. Thanks for the idea!

>
> How about...?
>
> protected void Application_Start(Object sender, EventArgs e)
> {
> Application["OkToRun"] = <code to check viable environment>;
> }
>
> protected void Session_Start(Object sender, EventArgs e)
> {
> if ((bool)Application["OkToRun"])
> {
> Response.Redirect("homepage.aspx", false);
> }
> else
> {
> Response.Redirect("errorpage.aspx", false);
> }
> }
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for environment variable? Fie Fie Niles Microsoft Windows 2000 7 16th Dec 2010 05:10 PM
check the temp environment variable bob494 Microsoft Outlook Discussion 3 29th Jan 2010 07:38 PM
Check XP machine status in a AD environment andy Microsoft Windows 2000 Active Directory 0 23rd Oct 2006 06:14 PM
Check XP machine status in a AD environment andy Microsoft Windows 2000 Active Directory 0 23rd Oct 2006 06:10 PM
How to check if USB ports (environment) available and accessible ?? Mark Spitzer Microsoft Windows 2000 4 2nd Dec 2003 02:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 AM.