How to access a property created in global.asax.cs?

I am reading two values ​​from web.config in Application_Startmine Global.asax.cs. String values ​​from the web.config file are assigned to their public properties, also defined in Global.asax.cs.

How can I access the properties in the global.asax.cs file from another class, method and namespace?

Update # 1 This is harder than I thought (or maybe I'm just complicating it). The class in which I want to reference these properties in a simple ol class library, and I do not have access to httpcontext (or I do not know how to access it).

+5
source share
2 answers

Global.asax.cs , web.config, global.asax.cs.

, Global.asax.cs , "".

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

        Application.Add("Foo", "Bar");

    }

, , Global static.

    public static string Abc { get; set; }
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

        Abc = "123";

    }
+1

Global .

var app = (Your.App.Namespace.Global)HttpContext.Current.ApplicationInstance;
var x = app.YourProperty;
+5

All Articles