Question

I'm a beginner in ASP.net, i did some research about Application state. I know about declaring new application state inside the Application_start event.

But when i looked inside MSDN library (which is not helpful at all unfortunately). I found this paragraph:

Alternatively, you can add objects to the StaticObjects collection via an declaration in your Web application's Global.asax file. Application state defined in this way can then be accessed from code anywhere in your application. The following example shows an object declaration for an application state value:

<object runat="server" scope="application" ID="MyInfo" 
    PROGID="MSWC.MYINFO">
</object>

You can add objects to the StaticObjects collection only in the Global.asax file. The collection throws a NotSupportedException if you attempt to add objects directly through code.

You can access members of objects stored in application state without having to reference the Application collection. The following code example shows how to reference a member of an object defined in the StaticObjects collection of application state. Notice that the label identifier defined in Global.asax is used as the variable name.

I really have no idea how to add objects to the StaticObjects collection via an <object runat="server"> declaration in your Web application's Global.asax file.

  1. How to add <object> tag?
  2. What is <object> tag in the first place?
  3. What is StaticObject collection?
  4. How to add "tags" inside a Global.asax (C# code) ?

I know my questions are very primitive but i really want to understand things well.

Was it helpful?

Solution

MSDN is not always right, especially some of the example code is often weird.

The XML code can be put into web.config file, whereas global.asax.cs contains handlers for different app lifecycle events, so you can achieve similar results programatically for example in Application_Start event handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top