Download presentation
Presentation is loading. Please wait.
Published byMaryann Arleen Johnson Modified over 9 years ago
1
Building Applications using ASP.NET and C# / Session 5 / 1 of 19 Session 5
2
Building Applications using ASP.NET and C# / Session 5 / 2 of 19 Session Objectives Discuss the Global.asax file Explain events in Global.asax file Use the Application object Use the Server object
3
Building Applications using ASP.NET and C# / Session 5 / 3 of 19Global.asax Stored in Root Directory of application Defines boundary of application Initialise application or session level variables Connect to databases Send cookies
4
Building Applications using ASP.NET and C# / Session 5 / 4 of 19 Events in Global.asax - 1 EventsFired When Application_OnStartFired when the first ASP.NET page in the current application directory (or its sub-directories) is called. Application_OnEndFired when the last session of the application ends. Also fired when the web application is stopped using the Internet Services Manger snap-in. Application_OnBeginRequestFired every time a page request begins (ideally when a page is loaded or refreshed). Application_OnEndRequestFired every time a page request ends (that is every time the page executes on the browser) Session_OnStartFired every time a new session begins. Session_OnEndFired when the session ends. For the various ways in which a session can end refer to the session on the Session object.
5
Building Applications using ASP.NET and C# / Session 5 / 5 of 19 Events in Global. asax - 2
6
Building Applications using ASP.NET and C# / Session 5 / 6 of 19 Application Object - 1 Represents an instance of an ASP.NET application. Object[varName] Application ["greeting"] = "Welcome to my World";
7
Building Applications using ASP.NET and C# / Session 5 / 7 of 19 Application Object - 2 void Application_OnStart(Object sender, EventArgs E) { Application ["greeting"] = "Welcome to my World"; } void Page_Load(Object Src, EventArgs E){ Response.Write(Application ["greeting"]); }
8
Building Applications using ASP.NET and C# / Session 5 / 8 of 19 Application Object - 3 void Application_OnStart(Object sender, EventArgs E) { Application ["Counter"] = 0; } void Page_Load(Object Src, EventArgs E){ Application["Counter"] = (Int32) Application ["Counter"] + 1; Response.Write("You are visitor number :" + Application ["Counter"]); } <FONT SIZE = 5 COLOR = RED>Welcome to my World
9
Building Applications using ASP.NET and C# / Session 5 / 9 of 19 Application Object - 4
10
Building Applications using ASP.NET and C# / Session 5 / 10 of 19 Controlling Access void Page_Load(Object Src, EventArgs E) { Application.Lock(); Application["Counter"] = (Int32) Application ["Counter"] + 1; Application.UnLock(); } This page has been visited times!!
11
Building Applications using ASP.NET and C# / Session 5 / 11 of 19Arrays void Application_Start(Object sender, EventArgs E) { String [] job = new String [4]; job[0]= "Faculty"; job[1]= "Programmer"; job[2]= "Salesman"; job[3]= "Manager"; Application ["j"] = job; } void Page_Load(Object Src, EventArgs E) { int i = 0; String[] k; k = (String[])Application["j"]; for (i = 0; i<k.Length;i++) { Response.Write(k[i] + " "); } }
12
Building Applications using ASP.NET and C# / Session 5 / 12 of 19 Server Object Execute and Transfer HTMLEncode URLEncode MapPath PropertyDescription ScriptTimeoutIs used to specify the period for which a script can run on the server before it is terminated. MachineNameIs used to get the machine name of the server. Server.property | method
13
Building Applications using ASP.NET and C# / Session 5 / 13 of 19 Execute Method void clicked (Object Src, EventArgs E){ Server.Execute("/test/ses6ex1.aspx");}
14
Building Applications using ASP.NET and C# / Session 5 / 14 of 19 Transfer Method Server.Transfer("/test/transfer.aspx");
15
Building Applications using ASP.NET and C# / Session 5 / 15 of 19 HTMLEncode Method Response.Write( Server.HtmlEncode(" is an example of a Heading tag ")); Server.HTMLEncode (string) Response.Write(" is an example of a Heading tag ");
16
Building Applications using ASP.NET and C# / Session 5 / 16 of 19 URLEncode Method - 1 Response.Write(Server.UrlEncode("http://localhos t/code/map.aspx")); Server.URLEncode (string)
17
Building Applications using ASP.NET and C# / Session 5 / 17 of 19 URLEncode Method - 2 void clicked (Object Src, EventArgs E) { String name = Server.UrlEncode("John Saunders"); Response.Redirect ("http://localhost/code/calendar.aspx?name=" + name); } void clicked (Object Src, EventArgs E) { String name = Server.UrlEncode("John Saunders"); Response.Redirect ("http://localhost/code/calendar.aspx?name=" + name); }
18
Building Applications using ASP.NET and C# / Session 5 / 18 of 19 URLEncode Method - 3 void clicked (Object Src, EventArgs E){ String name = Server.UrlEncode("John Saunders"); String password = Server.UrlEncode("king"); Response.Redirect("http://localhost/code/error.aspx?na me=" + name + " &password=" + password); } void clicked (Object Src, EventArgs E){ String name = Server.UrlEncode("John Saunders"); String password = Server.UrlEncode("king"); Response.Redirect("http://localhost/code/error.aspx?na me=" + name + " &password=" + password); }
19
Building Applications using ASP.NET and C# / Session 5 / 19 of 19 MapPath Method Response.Write( Server.MapPath("/encode.aspx")); Response.Write( Server.MapPath("encode.aspx")); Response.Write(Server.MapPath(Request.ServerVari ables.Get("PATH_INFO"))); Server.MapPath (path)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.