Processing Directives

i THE GLOBAL.ASAX FILE

ou can use processing directives in the Global.asax file to specify settings used in your application. The three classifications of directives are Application, Assembly, and Import directives. With the Application directive, you can set two attributes, Inherits and Description. The Inherits attribute is used to set which .NET base class the global.asax file uses for all instances of global.asax. The ASP.NET application compiler uses this information to compile a new application that extends the specified class. The Description attribute gives a short description of your application. You can place both attributes in the same directive.

The next directive that you could use is the Assembly directive. This directive links an assembly to the application. This makes classes in the assembly available to your application. Another directive that appears similar to the Assembly directive is the Import directive. You can use the Import directive to import .NET namespaces. The Import directive assumes that the assembly that contains the namespace is already available. After you import a namespace, you can reference classes in the namespace without giving the full qualification to the class.

As with page-level directives, you should place the application-level directives at the top of the Global.asax file. You should also place the directive name/value pair within the ASP.NET script delimiters.

USING THE IMPORT DIRECTIVE

Untitled Notepad

File Edit Format Help

File Edit Format Help

i Open...

Ctrl+O

Save

Ctrl+S

Save As...

USING THE IMPORT DIRECTIVE

Untitled Notepad

¡Untitled - Notepad file_Edi!_Eoima!_tldo-

□ Start the text editor to edit the Global.asax file.

-0 Click File O Open.

¡Untitled - Notepad file_Edi!_Eoima!_tldo-

Import Namespace=""|%^

<SCRIPT LANGUAGE="C#" RUNAT=t"Seiver">

void Appiication_Start() {

string stringSiteName = "M^ Application["appiicationSite

void Application_End() {

Applicationf'applicationSite

void Session_Start() {

Response.Wntef'Session Start e string stringUserGreeting = Session["sessionUserGree'

void Session_End() {

Session["sessionUserGree

□ Start the text editor to edit the Global.asax file.

-0 Click File O Open.

LH Click 0 to select the Code Templates directory and open the UsinglmportDirective GlobalTemplate.asax file.

□ Click Open to open the ^0 Type the ASP.NET script template. delimiters (<%%>) and press

Enter

Note: You can open another Global.asax file that you want to use as an import directive.

Lifetime Goals"; Name"] = stringSiteName;

/ent handler called.,.<br>"); 'Welcome to My Lifetime Goals'] ing"] = stringUserGreeting;

0 Position the insertion point after the first ASP.NET script delimiter (<%) and type a space followed by @ Import Namespace="".

Was this article helpful?

0 0

Post a comment