Web Application Events in ASP.NET

Web Application Events in ASP.NET – Web Application Events वे Events होते हैं, जो कि पूरे Web Application के Changes को Represent करते हैं। यानी जब हमें ऐसे Operations Perform करने होते हैं, जो Web Application के सभी Webpages पर समान रूप से Apply होते हैं, तो इस प्रकार के Events को Application Events के नाम से जाना जाता है।

Application Level Events को Global Application Class द्वारा Handle किया जाता है। इसलिए Global Application Class File Createकरने के लिए हमें Visual Studio में Create किए जाने वाले अपने Web Application में फिर से एक नया Item Add करना होता है, जिसके लिए हम PROJECT => Add New Item… Option को Click करते हैं और हमारे सामने फिर से निम्नानुसार एक Dialog Box Display होता है:

Web Application Events in ASP.NET WebForms in Hindi

सामान्‍यत: Visual Studio हमारे Application Events के लिए Create होने वाले “ Global Application Class” File का नाम Global.asax रखता है और हमें भी इस नाम को Change नहीं करना चाहिए।

हालांकि हम हमारी जरूरत के अनुसार इस नाम को Change भी कर सकते हैं, क्योंकि Visual Studio किसी Global Application Class File को उसके नाम से नहीं बल्कि उसके Extension से Identify करता है। यानी जिस किसी भी Class File का Extension .asax होता है, Visual Studio उस File को Global Application Class File की तरह ही Treat करता है।

अपने Global Application Class File का नाम Specify करने के बाद इस Dialog Box पर दिखाई देने वाले “Add” Button पर Click करते ही हमारे Visual Studio के Solution Explorer Sidebar में Global.asax नाम की एक नई File Add हो जाती है, जिसमें निम्नानुसार केवल एक Line का Code लिखा होता है:

[code]
<%@Application
    Codebehind=" Global.asax.cs"
   Inherits="EventsAndContexts. Global"
   Language="C#"
%>
[/code]

इस File में Specified Application Directive, ASP.NET Web Server को इस बात का Instruction देता है कि Code-Behind Class File में Specify किए गए Program Logic Codesको Application द्वारा Trigger होने वाले Events के Handlers की तरह Treat किया जाए।

जबकि इस Application Directive में Specified अन्‍य Attributes के Meaning वही हैं जो Page Directive के लिए थे। यानी Create होने वाली इस Global.asax File के साथ एक Code Behind File भी Associated रहती है जिसका नाम Global.asax.cs होता है।

इस Code Behind File में भी कुछ Automatically Generated Codes होते हैं, जो कि निम्नानुसार होते हैं:

[code]
File Name: Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace EventsAndContexts
{
  publicclass Global : System.Web.HttpApplication 
  {
    protected void Application_Start(object sender, EventArgs e)
    {
    }

    protected void Session_Start(object sender, EventArgs e)
    {
    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
    }
    
    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
    }

    protected void Application_Error(object sender, EventArgs e)
    {
    }

    protected void Session_End(object sender, EventArgs e)
    {
    }

    protected void Application_End(object sender, EventArgs e)
    {
    }
  }
}
[/code]

Application Events की ये Sequences उतनी Simple नहीं है, जितनी Page Events की Sequence थीं। इन Events में से कुछ Events केवल तब Trigger होते हैं, जब Application Start होता है, कुछ Events केवल तब Trigger होते हैं, जब Application कोई Request Receive करता है, जबकि कुछ अन्‍य Events इन दोनों Events के बीच Trigger होते हैं।

Applications Events को System.Web.HttpApplication के Parts के रूप में Define किया गया है, जो कि Global.asax Code-Behind Class की Base Class है और क्योंकि Automatic Event Wiring पहले से True Set रहता है, इसलिए ये बात Ensure हो जाती है इस Application Object के साथ Connected Events एक Event Handler को Represent कर रहा है। जैसे Application_Start(), Application_End(), आदि।

चलिए, Application Object द्वारा Provide किए जाने वाले विभिन्न Events में से Mostly Use किए जाने वाले Events की Working को समझने की कोशिश करते हैं।

Read more…

Web Application Events in ASP.NET

Application Start and End Events

Session Start and End Events

Authentication and Error Events

Application Request Events

Core ASP.NET WebForms in Hindi - BccFalna.com: TechTalks in Hindiये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook Core ASP.NET WebForms with C# in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी। 

Core ASP.NET WebForms in Hindi | Page:647 | Format: PDF

BUY NOW GET DEMO REVIEWS