471,066 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Application Start

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
Nov 19 '05 #1
16 3027
Have you tried making an httpmodule to do this?

KG

"Fernando Arámburu" <fe**************@speedy.com.ar> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #2
Well, you can implement a Custom HTTP Module:
http://msdn.microsoft.com/library/de...ttpmodules.asp

which has the init() method....

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Fernando Arámburu" <fe**************@speedy.com.ar> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #3
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Have you tried making an httpmodule to do this?

KG

"Fernando Arámburu" <fe**************@speedy.com.ar> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
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


Nov 19 '05 #4
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
"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:19**********************@msnews.microsoft.com ...
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Have you tried making an httpmodule to do this?

KG

"Fernando Arámburu" <fe**************@speedy.com.ar> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
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


Nov 19 '05 #5
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

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
escribió en el mensaje news:uH**************@TK2MSFTNGP15.phx.gbl...
Well, you can implement a Custom HTTP Module:
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcustomhttpmodules.asp
which has the init() method....

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Fernando Arámburu" <fe**************@speedy.com.ar> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
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


Nov 19 '05 #6
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
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #7
Static constructors are lazy-loaded...meaning it won't necessarily run on
application start, but rather when the first member (static or instance) of
the class is called...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:19**********************@msnews.microsoft.com ...
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
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #8
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

"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:19**********************@msnews.microsoft.com ...
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
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #9
Yes of course. But for many scenarios this is perfectly acceptable.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Static constructors are lazy-loaded...meaning it won't necessarily run
on application start, but rather when the first member (static or
instance) of the class is called...

Karl


Nov 19 '05 #10
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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

"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:19**********************@msnews.microsoft.com ...
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
}
}
-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #11
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
"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:20**********************@msnews.microsoft.com ...
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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

"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:19**********************@msnews.microsoft.com ...
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
}
}
-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #12
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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

"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:20**********************@msnews.microsoft.com ...
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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

"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:19**********************@msnews.microsoft.com ...

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
}
}
-Brock
DevelopMentor
http://staff.develop.com/ballen
> 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


Nov 19 '05 #13
> 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

-Brock
DevelopMentor
http://staff.develop.com/ballen
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

"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:20**********************@msnews.microsoft.com ...
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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

"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:19**********************@msnews.microsoft.com ...

> 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
> }
> }
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>> 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


Nov 19 '05 #14
> 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.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #15
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 ;)
"Brock Allen" <ba****@NOSPAMdevelop.com> escribió en el mensaje
news:21**********************@msnews.microsoft.com ...
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #16
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...

Nov 19 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by

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.