How to access static Global.asax members?

If we declare a variable staticin Global.asax, then how to access it on the page ASP.NET?

<script runat=server">

   public static object myObject = new MyClass();

   // Application_Start() and other stuff goes here.

</script>

And is it a good idea to store a global object (one instance for all requests)?

+5
source share
4 answers

It might be better to create your object as a singleton rather than placing it as a "global" object. Create it at the beginning of the application and destroy it at the end of the application. As long as you don't need this through web farms, you're pretty safe.

See this post and its comments.

http://weblogs.asp.net/jeff/archive/2007/09/21/how-do-you-get-a-true-singleton-in-an-asp-net-app.aspx

0

myObject global.asax ASP.NET,

Global.myObject
+4

ASP.NET. .

MyClass, , (, , , ).

ApplicationState, , Microsoft, .

0

:

ASP.global_asax

ASP.global_asax.DefaultModel.GetTable( " " );

0
source

All Articles