473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Check environment in application_start

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
Jan 10 '08 #1
5 1808
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
Jan 10 '08 #2
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
Jan 10 '08 #3
"MattB" <so********@yahoo.comwrote in message
news:5u*************@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

Jan 10 '08 #4
"MattB" <so********@yahoo.comwrote in message
news:5u*************@mid.individual.net...
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

Jan 10 '08 #5
Perfect. Thanks!

Matt

Mark Rae [MVP] wrote:
"MattB" <so********@yahoo.comwrote in message
news:5u*************@mid.individual.net...
>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);
}
}

Jan 11 '08 #6

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

Similar topics

1
by: AW | last post by:
Hi all, In my Application_Start, I'm initializing the application. ASP.Net calls my Application_Start on the first request, not on the following ones. However, if something goes wrong in my...
3
by: msnews.microsoft.com | last post by:
Hi What can you do with the errors occuring in global.asax in Application_Start (or Init) ? What is the best practice here ? What's the elegant solution in this case ? For now (I'm learning)...
7
by: Gordon Smith | last post by:
I have four (4) ASP.NET Web applications/Web sites on a IIS/6 - Windows Server 2003 production server. 3 of them work fine. I just installed the 4th one and it's Application_Start event is not...
6
by: Leslie | last post by:
I am attempting to handle errors by using Application_Error. This seems to work fine in most situations. However, if the exception occurs during the Application_Start method, the stand error...
4
by: Marc Missire | last post by:
Hi, I have an issue below I'd love help with, involving a static variable, Application_Start, and a background thread. In global.asax.cs I have a static variable (outside any method) with a...
8
by: bryan | last post by:
Is there any way I can get the application path (the one returned by Request.ApplicationPath) in the Application_Start method in Global.asax? Request is not valid there. On a related note, is there...
4
by: NoNickname | last post by:
Hi, I need to get a string from a COM component at application start. (It's a Long Story and I cannot change this fact.) In ASP.NET 1.1, I simply called this COM component in Global.asax.cs...
6
by: Joe Befumo | last post by:
I just created the default personal site project in Visual Studio 2005, and it worked perfectly -- very nice. Next, I'd like to import some stat-capture code that I have working in a Visual Studio...
5
by: Eirik Eldorsen | last post by:
I have a webpage that starts a thread on Application_Start in global.asax. I don't want to start start this thread when I am testing the application at localhost. How can I check if I am at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.