Check environment in application_start

Check environment in application_start

am 10.01.2008 20:17:24 von MattB

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

RE: Check environment in application_start

am 10.01.2008 21:38:04 von pbromberg

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
>

Re: Check environment in application_start

am 10.01.2008 21:41:39 von MattB

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
>>

Re: Check environment in application_start

am 10.01.2008 21:41:52 von mark

"MattB" wrote in message
news:5un9arF1istnvU1@mid.individual.net...

> 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

Re: Check environment in application_start

am 10.01.2008 21:50:07 von mark

"MattB" wrote in message
news:5une8mF1issihU1@mid.individual.net...

> Sometimes simplistic is best. Thanks for the idea!

How about...?

protected void Application_Start(Object sender, EventArgs e)
{
Application["OkToRun"] = ;
}

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

Re: Check environment in application_start

am 11.01.2008 01:00:52 von MattB

Perfect. Thanks!

Matt

Mark Rae [MVP] wrote:
> "MattB" wrote in message
> news:5une8mF1issihU1@mid.individual.net...
>
>> Sometimes simplistic is best. Thanks for the idea!
>
> How about...?
>
> protected void Application_Start(Object sender, EventArgs e)
> {
> Application["OkToRun"] = ;
> }
>
> protected void Session_Start(Object sender, EventArgs e)
> {
> if ((bool)Application["OkToRun"])
> {
> Response.Redirect("homepage.aspx", false);
> }
> else
> {
> Response.Redirect("errorpage.aspx", false);
> }
> }
>
>