Application Start

F

Fernando Arámburu

Hi , it´s me again.

I will take another way because yesterday I make a question and,
probably I didn´t make myself clear so you didn´t understand my question.

I want to know if there is any way to register a method to the
Application Start event. I know there is one way, in Global.asax writing
code in

Application_Start

but this way is not possible for me because I need to do it without
implementing those methods in global.asax

What i need is something like:

AnyDotNetFrameworkClass.ApplicationStart += new EventHandler(My_Method);

Do you know if ApplicacionStart event is declared somewhere on the
framework so I can register to it?
Thanks in advance

Fernando Arámburu
 
B

Brock Allen

HttpModules can't handle the Application_Start, Application_End, Session_Start
or Session_End events. They aren't proper events -- there's code in ASP.NET
that's hard coded to look for these and call them directly.
 
F

Fernando Arámburu

Thanks for the answer.
Even though it does not help too much to my problem, just thanks for telling
me that bad thing I was thinking on: "it´s only a hardcode and there are no
events"
REALLY BAD NEWS.
Thanks again.

Fernando Arámburu
 
F

Fernando Arámburu

HttpModule can´t manage Application Start and Session Start. I only need to
catch those moments and I can´t do that in Global.asax file because I can´t
put code in user code.
I´m working on a Framework that programmers use to improve some ASP.NET
features I can´t put code in user code.
Thanks for the answer.

Fernando Arámburu
 
B

Brock Allen

Why can't you just have a type initializer (static constructor)? This is
an easy way to get one-time initilization semantics.

public class MyClass
{
static MyClass()
{
// do your one-time init here
}
}
 
F

Fernando Arámburu

And where am I working with Application Start and Session Start? I mean, you
are talking about one-time initialization that is completely different from
what i need. I need to some things when Application Start and when Session
Start.

Fernando Arámburu
 
B

Brock Allen

Ah, I wasn't aware you also needed Session_Start semantics -- your original
post didn't mention this at all.

What is it that you need to do at application startup?

As for the Session_Start, you may be out of luck given ASP.NET's implementation
that calls Session_Start in global.asax.
 
F

Fernando Arámburu

I need to load some things to the Application object collection.I need to
create some object and put the most important one on the Application objects
collection so I can get it on every request.

I don´t understand what you say about Session_Start and out of luck ......
Can you say that in other words?
Just one thing, I can't touch Global.asax file because I need to compile
what I´m doing an generate a closed dll so Global.asax file can not be
included. The only thing I can do with Global.asax is that Global class
defined there inherits from one MyHttpApplication written by me and that
MyHttpApplication inherits from original System.Web.HttpApplication

Thanks in advance.

Fernando Arámburu
 
B

Brock Allen

Why does your application wide data need to be in the ASP.NET Application
object? If you can't find a workaround to your problem, keeping that data
in static variables will have the same effect.

So you do have control over the global.asax? Meaning, you can specify the
Inherits directive? If so, then you can do these things you're talking about
-- in your HttpApplication derived class, add Session_Start and whatever
else you need. Didn't you try this already? I don't have the original post,
so my apologies if you've already mentioned that.
 
F

Fernando Arámburu

Why does your application wide data need to be in the ASP.NET Application
object? If you can't find a workaround to your problem, keeping that data
in static variables will have the same effect.

The problem with static variables is that initialization ocurrs with the
first call to an object of this class and I want to load those object when
the application start. Even though, for now is a good solution.
So you do have control over the global.asax? Meaning, you can specify the
Inherits directive? If so, then you can do these things you're talking about
-- in your HttpApplication derived class, add Session_Start and whatever
else you need. Didn't you try this already?.

I tried this solution. The problem I found with this is that if I use
Session_Start method (just for example I put Session_Start, with
Application_Start is the same problem) then programmers can´t write on their
Session_Start method of the Global class, because I have override their
Session_Start method.
Do you understand what I try to say?

Do you have any idea of how I can do that in that intermediate class
MyHttpApplicaiton?
I don't have the original post, so my apologies if you've already
mentioned that
Don´t worry about the originial post and thanks a lot for answer,

Fernando Arámburu
 
B

Brock Allen

The problem with static variables is that initialization ocurrs with
the first call to an object of this class and I want to load those
object when the application start. Even though, for now is a good
solution.

Are you sure you need it to run immediaetly when the app starts up and can't
wait until the first time you need this application wide data? I'd imagine
in 90% of the cases the difference between the two (time-wise) won't be a
whole heck of a lot... But of course it's not called until the first time
it's requested... which as I mentioned before, is acceptable in many scenarios.
The only sort of scenario where I don't see this being acceptable is where
your Application_Start needs (or the equivalent thereof) needs to push some
information out of the application such as sending an email, or going out
to the database to log that the application has started, or write to the
event log, etc... So yeah, those scenarios it's not the right approach for.
But if what you're doing is simply preloading and/or initializing app-wide
data, then the static ctor should be fine. Anyway, it's your app, so you
know best which of these approaches is right for you.
I tried this solution. The problem I found with this is that if I use
Session_Start method (just for example I put Session_Start, with
Application_Start is the same problem) then programmers can´t write on
their
Session_Start method of the Global class, because I have override
their
Session_Start method.
Do you understand what I try to say?
Do you have any idea of how I can do that in that intermediate class
MyHttpApplicaiton?

It sounds like you're going to have to build your own publish/subscribe eventing
mechanism for these notifications to allow the flexiblity you have been talking
about.
 
F

Fernando Arámburu

Hi again,

Thanks very much for all the answers.

About the first point of the conversation, you are probably on the right
way. I mean, I want to do it on the Application Start but I think that I can
run that script as static so thanks a lot.

About the second point, yes, you are completelly right. It sounds like I
will have to build my own publish/subscribe eventing mechanism for these
notifications to allow the flexiblity I have been talking about.

Thanks a lot again and I wish I could help you in something
bye for now.

Fernando Arámburu
PS: I put on my favourites your blog so I start reading something about
ASP.NET 2.0 ;)
 
S

spinthemoose

If you are developing an extensible framework, perhaps you could write
your own Global.asax class with protected Application_Start and
Session_Start members so that when your users inherit from your global
class, they can override your App_start and Ses_start methods as
needed, calling base.app_start or base.ses_start as needed.

This seems to be the way many OO frameworks are designed.

Alternatively, build your own App_start and Ses_start methods and
expose events that your users can hook into so that they don't need to
call these methods directly. This would seem to let you control the
timing of whether your method or theirs gets executed first...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top