In this video Chris Pels will show how to create an Application Class File (Global.asax) that contains application level event handlers such as Application_Start and Application_BeginRequest. Then the sequence of application level events in the application lifecycle will be discussed as a basis for determining where certain types of operations would be best performed during the application lifecycle.
The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video
Minute 0
Role just as this you will learn how to use Haitian little offense in ASP net this gets sorted by creating a website and this simple websites in Visual Basic and if you download the sample source code you also see these same demo website I m doing here in Visual Basic and see sharp in order to use application level events in an ASP net website you need to have what s called an application level class and you add that class to website by editing a file called global aspx Citicorp to the website and at a new item to see here on the list of templates is one called global application class and that adds the global ASA X Files Sawyer that tour what
Minute 1
Website of the global ASA ex is a class that extends the HT keep the application class and the first time a user visits the website the global ASA ex is compiled into a class in a subsequent visits that class is automatically loaded so does have to be recompiled however for example if you change the global ASA accident replace it up on your website then the next time that a user visited the site he would get recompiled again and stored on the server as you can see Visual Studio has added several stubs for some the application level events in a following naming convention is very similar to the page level of density might be familiar with so its application_in the name of the event soon as Casey at the start and an era in you also see that we have some session state offense here so the global ASA ex is also where you would add code to have been
Minute 2
Tap and when you begin and end the session plus get started by showing how you would add some code to one of these events in which might use them for a number to come back and talk little bit about some the other events are available in the sequence these events occur in so let s do the applications start event ending here what we re going to do is store several values in the application state so will say application and the first from the store is the title of the application in a set that equal to highway use application level events and the second one will produce the counter for the number of users or say application number users and will set that to zero in
Minute 3
Delay and let s put a third one called application counter and this is just in account the number of times the application has been accessed will set that to zero by default as well just format the code you re little bit forgone into our next step want to do is add some code to the application begin requested and to do that I need to add a sub here for that event is one of when they do is just copy the applications start and pasted down here below and then we ll change the name of the event has said the naming conventions this application_event name just some simple just put begin requests
Minute 4
Or application variable and application state so we ll do is to say application application counter is equal to and this is an integer but it s stored as an objects organ have to change its type so we ll do is we ll say seat type and now get the application counter and will convert that to an insecure in limbo incremented by one know what we should do here as well and is licensed for accessing the application for a blue one and make sure no one else is doing that slightly below lock and unlock and
Minute 5
And once for gun wallet locket knowest do something similar for the number of users down in these sessions start so will copy this could end the session start pace in here and let me to scroll up and won t change the application counter to the number of users so what this will do is every time the session starts to increment the counter for the number of users is now let s use the information restoring in its application variables are the aspx page in what I ll do is purchase through the code bind let s go to the pre render event at that and what we ll do is just right out a few of those pieces of information
Minute 6
Sadr Raitt and personals at his title equals and with that will go into the application object and get the title information that we stored this convert that to a string and for the second one will get the counter which is the application counter and will just get that value string as well and then for the third one will will do is just right out the users are able to hold a user as equals to them will get that value from the application object
Minute 7
Now or what is are just going to put a few breakpoints so we can see when these different events are fired will put here in the applications start begin request and down in the session start to let startup the website and will see that the first event is the applications start as you might expect simple store information will let it run from here next hit the beach in request as the requests for the default aspx page is processed and then we start a session so we reach these sessions start at the end let it run from here and you can see we have be the title of the events or application counter of one and the users equals to want from it do is just refresh the page so we should get at another root
Minute 8
But we should not increment the users because that s in this same session preference is to let things run here begin request and as you can see the counter equals to indicate that the begin request event was hit a second time as he saw it with these three events that we implemented that there is a specific sequence in which these events are fired such an important consideration when you re designing your application and overall there is almost 20 application level events and I m not indigo for them one by one here or visit page or an MSDN dad has a good overview of the ASP net page life cycle as well as some information about the application level events let s go over and take quick look at that here s the page and I ll put a link to this page in the source code as comment so you can access it when you download the sample source code
Minute 9
Tell with an overview of the lifecycle of an ASP net application goes to the major stages that occur and down here when it gets to this stage is what s called the processing by the HT key the application pipelines and during this part of the processing is where the application level events occur in senior number three is the begin request event that we used in the demo just a few minutes ago and that s followed by a whole host of additional events in his events related to authentication authorization to caching than some about state that session state and down your number 15 is the actual processing by the handler and for example it s a page of this is where the page processing it occurs multipage level of and so are fired and then that s followed by several posts handling requests for the
Minute 10
State and some other aspects of the application lifecycle is a section here about the lifecycle events in the global ASA asked that we ve been talking about and it lists the major start and end events for the application and it is right down here and you can see here is the application_event name convention that we talked about for specifying the events in your global ASA text file legal appear to the top of our script and will display the comment line and I ll paste in the URL right here and open no right above it that says ASP net
Minute 11
Or event name and then insert the appropriate code to our process for that event and we did some relatively simple operations here just writing to the application state object because of a pretty broad nature of events that are provided you can really intervene and do some pre powerful things at various points in the page processing if you ever need to do so so that the real focus in using application level events is in learning what the page lifecycle contains for an ASP net webpage and then deciding which points in the process what you need to intervene to encourage you to download the sample source code is said it s available both in Visual Basic as we done here and in C sharp I also encourage you to read the MSDN article on the link that put the top of the script here online sex and get a good understanding of the
Minute 12
Lifecycle and ASP net this is Chris tells thanks for watching this video and how to use application level events in ASP net of oral
Click here to go to original video page
Sunday, August 31, 2008
Video: How Do I: Create and Use Application Level Events in ASP.NET
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment