Global.asax file. Agenda What is Global.asax file How to add the Global.asax file What are the default events available Explanation to Application_Level.

Slides:



Advertisements
Similar presentations
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Advertisements

CIS 451: ASP Sessions and Applications Dr. Ralph D. Westfall January, 2009.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
Working with Session and Application Objects. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and.
Creating web service (and client application) with Visual Studio 2008 Create web service project New project->web->ASP.NET web service application (with.
Tutorial -01. Objective In this session we will discuss about : 1.What is MVC? 2.Why MVC? 3.Advantages of MVC over ASP.NET 4.ASP.NET development models.
Role based Security in.NET By By Aasia Riasat Aasia RiasatCS-795.
11 ASP.NET Controls Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
IT533 Lectures Configuring, Deploying, Tracing and Error Handling.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 8: WebForms — Web-based.
Introduction to.Net and ASP.Net Course Introduction Build Your Own ASP.Net Website: Chapter 1 Microsoft ASP.Net Walkthrough: Creating a Basic Web Forms.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Global web applications1 Adapting ASP.NET web applications to work in different cultures.
JavaScript & jQuery the missing manual Chapter 11
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Overview of Previous Lesson(s) Over View  Server controls are small building blocks of the graphical user interface, which includes  Text boxes  Buttons.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Welcome  30 Question & 30 Minutes  Question Will Move Automatically After 1 Min Your Exam Start Now Lecturer : Zalak Thakrar.
© 2008 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
Beginning Web Site Development Module 1 – Dynamic Web Site Development Fundamentals of building dynamic Web sites with ASP.NET 2.0 and C# Version.
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
ASP Hello, world. ServerClient Response Request A form.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Managing State.
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
CSCI 6962: Server-side Design and Programming Introduction to Active Server Pages.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
Tracing 1www.tech.findforinfo.com. Contents Why Tracing Why Tracing Tracing in ASP.NET Tracing in ASP.NET Page Level tracing Page Level tracing Application.
© Chinese University, CSE Dept. Distributed Systems / Simple Example Open Microsoft Visual Studio 2005:
1 CS 3870/CS 5870 Note04 Session Variables and Post Back.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Unit 3: Adding Code to a Microsoft ASP.NET Web Form.
Working with the Application Object. Session VS Application Object The Session object helps to preserve data on a per user basis. What if we want to initialize.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
Dynamic Dropdown Lists 1. Objectives You will be able to Use Dropdown Lists to solicit multiple choice user input in an ASPX web page. Populate a Dropdown.
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
Introduction to ASP.Net ISYS 512. ASP.NET in the.NET Framework 1. The client requests a web page. 2. The web server locates the page. 3. If the page is.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
Introduction to Web Services. Examples Using a Web Service Creating a new Web Service.
BIT 285: ( Web) Application Programming Lecture 06: Thursday, January 22, 2015 Page Object, The Lifetime of a Web Application, Application State and Session.
1 Getting Started with C++. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Visual Studio 2008.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
Module 14 Application Settings, State, and Life Cycle.
Module 4: Creating a Web Application with Web Forms
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
Working With ASP.NET Application. Create a new virtual directory The procedure to create a new virtual directory Internet Services Manager Right click.
ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the.
Building Applications using ASP.NET and C# / Session 5 / 1 of 19 Session 5.
PHP Session ISYS 475. Session The web server starts a session when a visitor visiting your web site and assigns a unique id, the session id for the session.
11 ASP.NET Server Controls Beginning ASP.NET in C# and VB Chapter 4.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Overview of Previous Lesson(s) Over View  ASP is a technology that enables scripts in web pages to be executed by an Internet server.  ASP.NET is a.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
 ASP.NET provides an event based programming model that simplifies web programming  All GUI applications are incomplete without enabling actions  These.
Creating a Web Site Creating a new Web site Defining and using folders Creating and editing Web pages Viewing pages in a Web browser.
ASP.NET State Management Overview Prepared By Manish Kumar Aery(IM66) Department of computer Application IET Bhaddal (Ropar)
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Session Variables and Post Back
Data Virtualization Tutorial… CORS and CIS
Creating Session By huda AlSuwailem.
© 2016, Mike Murach & Associates, Inc.
Working with Session and Application Objects
5/6/2019 Session 8.2 Postback, ViewState
Caching.
Configuring .NET Web Applications
Presentation transcript:

Global.asax file

Agenda What is Global.asax file How to add the Global.asax file What are the default events available Explanation to Application_Level Events Example 1 :To display Server time Example 2:To Create Customized header Example 3:To display the Session ID Example 4: To display the number of hits

3 What is Global.asax file? It is also known as the ASP.NET application file It is an optional file with VS 2005 editor What does it consists of? –It consists of the code for responding to application level and session level events raised by ASP.NET –ASP.NET is configured such that any direct URL request to global.asax file is rejected

4 How to add? Its simple, Right click on the solution explorer in visual studio editor -> Add New Item -> Select "Global Application Class" - > press "Add" Button

5 Global.asax file.

6 Application Level Events Application_Start - This method will get fired when First time the application and web server (eg. IIS ) starts, That means If the IIS recycle or restart again then this event also will be fired. Application_End - This method will be fired when When application started shut down.

7 Application Level Events Application_Error - This event will be fired when there is any exception occurred in the application during run time. This event method is one of most important method used by most of the web developer. Session_Start - This event will be fired when a new user request a page from the server. That means for every user request the page this event will be fired. Session_End - This code will be fired when session end for a use.

8 Application Level Events Application_OnBeginRequest - This event will be fired for each request the application receives,just before the page is executed Application_OnEndRequest - This event will be fired for each request the application receives,just after the page is executed

9 Example 1 To display the server time globally throughout all the web forms using the Application_OnBeginRequest event void Application_OnBeginRequest(object sender, EventArgs e) { Response.Write("This page was servered at" + DateTime.Now.ToString()); }

10 Example 2 To display a custom header and footer using the Application_OnBeginRequest and Application_OnEndRequest protected void Application_BeginRequest(Object sender, EventArgs e) { Response.Write(" Welcome to my website! " ); Response.Write(" This is my header that comes from Application level " ); Response.Write(" ");}

11 Example 2 Contd.. Customized footer protected void Application_EndRequest(Object sender, EventArgs e) { int yearDate ; string dateStr; yearDate = System.DateTime.Now.Year; dateStr = yearDate.ToString(); Response.Write(" "); Response.Write("Copyright 2002-" + dateStr ); Response.Write("This is my customer footer that from Application level" ); Response.Write(" "); }

12 Example 3 To display the unique session Id for each user using the Session_Start Event void Session_Start(object sender, EventArgs e) { Session.Add("SomeValue", Session.SessionID); } protected void Page_Load(object sender, EventArgs e) { Label1.Text = "Your Session ID is" + Session["SomeValue"].ToString(); }

13 Example 4 To display the number of hits or the usercount Initialise the user count void Application_Start(object sender, EventArgs e) { Application.Add("userCount", 0); }

14 Increment the counter and display in the webform void Session_Start(object sender, EventArgs e) { int userCount = int.Parse(Application.Get("userCount").ToString()); userCount++; Application.Set("userCount", userCount); } protected void Page_Load(object sender, EventArgs e) { Page.Response.Write("Usercount:" + Application.Get("userCount").ToString()); }

15 Check out for the Demo

16 Session Useful methods: Session.Clear() – Clears all values from session, but leaves session active Session.Abandon() – Ends the current session. Read session Session(“message”) = “Hello” Set session txtHello.text = Session(“message”)