In The Globalasax File

ou can use the <object> tag in the Global.asax file to declare an object for use throughout your ASP.NET application. You should place the <object> tag outside the code declaration blocks. Therefore, you can place the <object> tag before or after the <script> tags, but not before any processing directives (<%@ Directive %>). For more about processing directives, see page 216.

The scope of the server-side objects are either for the entire application, per application instance, or per user session. You can set this using the scope attribute. When the scope attribute is set to application, there is a single object that is available for all users, on every page, at any time. When the scope is set to appinstance, there are multiple objects. There is one for each application instance, which is available to all users, on every page, at any time. When set to session, each user session manages a unique copy of the object.

Because of the scope of these variables, you should use caution when deciding what you place into memory. Use Session and Application level scope with caution. See pages 222 to 229 to see other issues associated with using the Application object and Session objects.

USING SERVER-SIDE OBJECTS IN THE GLOBAL.ASAX FILE

q Untitled - Notepad

File Edit Format Help q Untitled - Notepad

File Edit Format Help

New

Ctrl+N 1

Open...

Ctrl+O

Save

Ctrl+S I

Save As...

Print... HEffll

JJ2<J

Print... HEffll

JJ2<J

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

□ Click Open to open the template.

File name:_|DeciareSaver5lde0biectG^

□ 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 DeclareServer SideObjectGlobal Template.asax file.

□ Click Open to open the template.

Note: You can open another Global.asax file that you want to use as a server-side object.

"3

Click where you want to declare a server-side object and type <OBJECT RUNAT="Server".

Note: Objects must be declared outside the <SCRIPT> tags.

L0 Type SCOPE= and the scope of the object.

Note: The scope of an object can be Session, Application, or AppInstance.

'-Q Type ID= and the name you want to reference the object by within your ASP pages.

Was this article helpful?

0 0

Post a comment