Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC How to access a property in the Global.asax file from the Controller?

in the Global.asax file, I manage some threads, and - from the Controller - I need to invoke an event of the one's thread. Is it possible to have access to that thread ?

like image 945
Tony Avatar asked Dec 06 '22 22:12

Tony


1 Answers

You could use the application state to store some object that will be shared among all users of the application:

protected void Application_Start()
{
    Application["foo"] = "bar";
    ...
}

and inside your controller you can access this property:

public ActionResult Index()
{
    var foo = HttpContext.Application["foo"] as string;
    ...
}
like image 176
Darin Dimitrov Avatar answered Feb 01 '23 12:02

Darin Dimitrov