By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

Life cycle of ASP .NET Application

P: n/a
jim
Hi All,

I like to know the life cycle of an ASP .NET Application( incudieng server
application, such as .NET Web Service). That means from initialization to
fully running and how to reboot it or shut it down. Including how to
establish the running environment( current working folder, ...etc) for each
ASP .NET application.

Because in my ASP .NET application, there are a lot of modules. Some were
developed by using VC#, others using VC++ .net. In these module, it may using
LoadLibrary to load third party library. So, I need to know the current
environment of my ASP .NET application. And also, there are some
initialization task will be done in Application_Start( which is
Application-level ), So I also need to know the full life cycle of my ASP
..NET application to make sure that it can be initialized, unintialized, or
reinitialized properly.

Anybody have any advice would be great appreciated.

Thanks a lot,

Jim
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Check out this sample chapter from Programming ASP.NET book by Dino,
http://www.microsoft.com/mspress/boo...pchap/6667.asp

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"jim" <ji*@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
Hi All,

I like to know the life cycle of an ASP .NET Application( incudieng server
application, such as .NET Web Service). That means from initialization to
fully running and how to reboot it or shut it down. Including how to
establish the running environment( current working folder, ...etc) for each ASP .NET application.

Because in my ASP .NET application, there are a lot of modules. Some were
developed by using VC#, others using VC++ .net. In these module, it may using LoadLibrary to load third party library. So, I need to know the current
environment of my ASP .NET application. And also, there are some
initialization task will be done in Application_Start( which is
Application-level ), So I also need to know the full life cycle of my ASP
.NET application to make sure that it can be initialized, unintialized, or
reinitialized properly.

Anybody have any advice would be great appreciated.

Thanks a lot,

Jim

Nov 19 '05 #2

P: n/a
jim
Thank you -- Saravana,

I like to know the whole life cycle of ASP .NET application, not just a
specific web pages. For example, how IIS lanching the ASP .NET application,
which the instance of Global class will be created and the related
Application_Start method will be invoked. Actually, that means the life cycle
of the instance of Global class in ASP .NET application. When it will be
created and when it will be destroied. Who are responsible to create it?

Thanks a lot,

Jim
"Saravana" wrote:
Check out this sample chapter from Programming ASP.NET book by Dino,
http://www.microsoft.com/mspress/boo...pchap/6667.asp

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"jim" <ji*@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
Hi All,

I like to know the life cycle of an ASP .NET Application( incudieng server
application, such as .NET Web Service). That means from initialization to
fully running and how to reboot it or shut it down. Including how to
establish the running environment( current working folder, ...etc) for

each
ASP .NET application.

Because in my ASP .NET application, there are a lot of modules. Some were
developed by using VC#, others using VC++ .net. In these module, it may

using
LoadLibrary to load third party library. So, I need to know the current
environment of my ASP .NET application. And also, there are some
initialization task will be done in Application_Start( which is
Application-level ), So I also need to know the full life cycle of my ASP
.NET application to make sure that it can be initialized, unintialized, or
reinitialized properly.

Anybody have any advice would be great appreciated.

Thanks a lot,

Jim


Nov 19 '05 #3

P: n/a
An ASP.NET Framework application is created the first time
a request is made to the server; before that, no ASP.NET code
executes.

When the first request is made, a pool of HttpApplication
instances is created and the Application_Start event is raised.

The HttpApplication instances process this and subsequent requests,
until the last instance exits and the Application_End event is raised.

Usually that only happens when you use iisreset.exe to force
an IIS stop/start, when you shutdown the server, or when a
fatal error which stops IIS occurs.

The life cycle of a Web application would consist of these events:

Application_Start is raised only once during an application's lifetime,
on the first instance of HttpApplication. An application starts the first
time it is run by IIS for the first user. In your event handler you can
initialize a state that is shared by the entire application.

Session_Start is raised at the start of each session if you
enable Sessions. Here you can initialize session variables.

Application_BeginRequest is raised at the start of an individual request.
Normally you do your request processing in the Page class.

Application_EndRequest is raised at the end of a request.

An application executes events that are handled by modules
or user code defined in the global.asax file in the following sequence:

BeginRequest
AuthenticateRequest
AuthorizeRequest
ResolveRequestCache
[A handler (a page corresponding to the request URL) is created at this
point.]
AcquireRequestState
PreRequestHandlerExecute
[The handler is executed.]
PostRequestHandlerExecute
ReleaseRequestState
[Response filters, if any, filter the output.]
UpdateRequestCache
EndRequest

Session_End is raised at the end of each session,
if you have enabled Sessions.

Application_End is raised at the end of an application's lifetime,
when the last instance of HttpApplication shuts down.

Hope this helps...

Juan T. Llibre
ASP.NET MVP
===========
"jim" <ji*@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
Hi All,

I like to know the life cycle of an ASP .NET Application( incudieng server
application, such as .NET Web Service). That means from initialization to
fully running and how to reboot it or shut it down. Including how to
establish the running environment( current working folder, ...etc) for
each
ASP .NET application.

Because in my ASP .NET application, there are a lot of modules. Some were
developed by using VC#, others using VC++ .net. In these module, it may
using
LoadLibrary to load third party library. So, I need to know the current
environment of my ASP .NET application. And also, there are some
initialization task will be done in Application_Start( which is
Application-level ), So I also need to know the full life cycle of my ASP
.NET application to make sure that it can be initialized, unintialized, or
reinitialized properly.

Anybody have any advice would be great appreciated.

Thanks a lot,

Jim


Nov 19 '05 #4

P: n/a
instances of Global application are stored in a pool. they are created on
page references. the first instance is created on the first page request to
the site, which fire the Start event. additional instances are only created
when more than 1 page request is in use. when these instaces are created, no
event is fired. while the pool may get pruned, the life of the global
application is from the 1st page request until the application domain is
unloaded. the domain will be unloaded if the timeout occurs (to long between
page requests), a recycle event - your app is using too many resources, a
file change or a iis reset.

-- bruce (sqlwork.com)

"jim" <ji*@discussions.microsoft.com> wrote in message
news:D5**********************************@microsof t.com...
| Thank you -- Saravana,
|
| I like to know the whole life cycle of ASP .NET application, not just a
| specific web pages. For example, how IIS lanching the ASP .NET
application,
| which the instance of Global class will be created and the related
| Application_Start method will be invoked. Actually, that means the life
cycle
| of the instance of Global class in ASP .NET application. When it will be
| created and when it will be destroied. Who are responsible to create it?
|
| Thanks a lot,
|
| Jim
|
|
| "Saravana" wrote:
|
| > Check out this sample chapter from Programming ASP.NET book by Dino,
| > http://www.microsoft.com/mspress/boo...pchap/6667.asp
| >
| > --
| > -Saravana
| > http://dotnetjunkies.com/WebLog/saravana/
| > www.ExtremeExperts.com
| >
| >
| >
| > "jim" <ji*@discussions.microsoft.com> wrote in message
| > news:66**********************************@microsof t.com...
| > > Hi All,
| > >
| > > I like to know the life cycle of an ASP .NET Application( incudieng
server
| > > application, such as .NET Web Service). That means from initialization
to
| > > fully running and how to reboot it or shut it down. Including how to
| > > establish the running environment( current working folder, ...etc) for
| > each
| > > ASP .NET application.
| > >
| > > Because in my ASP .NET application, there are a lot of modules. Some
were
| > > developed by using VC#, others using VC++ .net. In these module, it
may
| > using
| > > LoadLibrary to load third party library. So, I need to know the
current
| > > environment of my ASP .NET application. And also, there are some
| > > initialization task will be done in Application_Start( which is
| > > Application-level ), So I also need to know the full life cycle of my
ASP
| > > .NET application to make sure that it can be initialized,
unintialized, or
| > > reinitialized properly.
| > >
| > > Anybody have any advice would be great appreciated.
| > >
| > > Thanks a lot,
| > >
| > > Jim
| > >
| > >
| >
| >
| >
Nov 19 '05 #5

P: n/a
jim
Thanks for your help --- Juan,

I have another question: How can I access the Instance of Global which is
inherite from httpApplication class in my ASP.NET page code?

Thanks in advance.
Jim
"Juan T. Llibre" wrote:
An ASP.NET Framework application is created the first time
a request is made to the server; before that, no ASP.NET code
executes.

When the first request is made, a pool of HttpApplication
instances is created and the Application_Start event is raised.

The HttpApplication instances process this and subsequent requests,
until the last instance exits and the Application_End event is raised.

Usually that only happens when you use iisreset.exe to force
an IIS stop/start, when you shutdown the server, or when a
fatal error which stops IIS occurs.

The life cycle of a Web application would consist of these events:

Application_Start is raised only once during an application's lifetime,
on the first instance of HttpApplication. An application starts the first
time it is run by IIS for the first user. In your event handler you can
initialize a state that is shared by the entire application.

Session_Start is raised at the start of each session if you
enable Sessions. Here you can initialize session variables.

Application_BeginRequest is raised at the start of an individual request.
Normally you do your request processing in the Page class.

Application_EndRequest is raised at the end of a request.

An application executes events that are handled by modules
or user code defined in the global.asax file in the following sequence:

BeginRequest
AuthenticateRequest
AuthorizeRequest
ResolveRequestCache
[A handler (a page corresponding to the request URL) is created at this
point.]
AcquireRequestState
PreRequestHandlerExecute
[The handler is executed.]
PostRequestHandlerExecute
ReleaseRequestState
[Response filters, if any, filter the output.]
UpdateRequestCache
EndRequest

Session_End is raised at the end of each session,
if you have enabled Sessions.

Application_End is raised at the end of an application's lifetime,
when the last instance of HttpApplication shuts down.

Hope this helps...

Juan T. Llibre
ASP.NET MVP
===========
"jim" <ji*@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
Hi All,

I like to know the life cycle of an ASP .NET Application( incudieng server
application, such as .NET Web Service). That means from initialization to
fully running and how to reboot it or shut it down. Including how to
establish the running environment( current working folder, ...etc) for
each
ASP .NET application.

Because in my ASP .NET application, there are a lot of modules. Some were
developed by using VC#, others using VC++ .net. In these module, it may
using
LoadLibrary to load third party library. So, I need to know the current
environment of my ASP .NET application. And also, there are some
initialization task will be done in Application_Start( which is
Application-level ), So I also need to know the full life cycle of my ASP
.NET application to make sure that it can be initialized, unintialized, or
reinitialized properly.

Anybody have any advice would be great appreciated.

Thanks a lot,

Jim


Nov 19 '05 #6

P: n/a
re:
Thanks for your help --- Juan,

No sweat, Jim. Glad to be able to assist.

re: How can I access the Instance of Global which is
inherited from httpApplication class in my ASP.NET
page code?
If you're using codebehind for your Global.asax,
you'd need to call it like this in Global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="YourApplicationName.Global" %>

That would assume that your codebehind for the ASP.NET
Application named "YourApplicationName" includes code
like this :

Global.asax.cs
---------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
namespace YourApplicationName

{
/// <summary>
/// Summary description for Global.
/// </summary>

public class Global : System.Web.HttpApplication

{
protected void Application_Start(Object sender, EventArgs e)

{
///Code for Application_Start goes here
}

protected void Session_Start(Object sender, EventArgs e)
{
///Code for Session_Start goes here
}

protected void Session_End(Object sender, EventArgs e)

{
///Code for Session_End
}

protected void Application_End(Object sender, EventArgs e)

{
///Code for Application_End goes here
}

}
}
Again, this assumes that your Application "/YourApplicationName"
has been created and that you can access it as :

http:/www.yourwebserver.com/YourApplicationName/

If you were doing this for an ASP.NET Application called "MyApp",
you could use this code in global.asax.cs :

using System.Web;
using System.Data;
public class MyApp : HttpApplication
{
public void Application_Start ()
{
DataSet ds = new DataSet ();
ds.ReadXml ("GlobalData.xml");
Application["GlobalData"] = ds;
}
}

Then, you could call it in Global.asax, like this :

<%@ Application Inherits="MyApp" %>

and you could reference Application["GlobalData"]
in your code in any aspx page as the source for
your Global Data.

Important: your application *must* have
been compiled in order for this to work OK.

Otherwise, you'll get an error message.

If you're not using codebehind, take a look at VB\Global.asax,
VB\Application2.aspx and VB\SchemaData.xml at :

http://samples.gotdotnet.com/quickst...plication2.src

If you use C#, there's links to the C# files, too.

There's a full example of setting a Global DataSource
in Global.asax, and retrieving it in an aspx page.
It's easier than it looks in this message. ;-)

Juan T. Llibre
ASP.NET MVP
===========
"jim" <ji*@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com... Thanks for your help --- Juan,

I have another question: How can I access the Instance of Global which is
inherite from httpApplication class in my ASP.NET page code?

Thanks in advance.
Jim
"Juan T. Llibre" wrote:
An ASP.NET Framework application is created the first time
a request is made to the server; before that, no ASP.NET code
executes.

When the first request is made, a pool of HttpApplication
instances is created and the Application_Start event is raised.

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.