Does asp.net MVC have Application variables?

后端 未结 6 2210
感动是毒
感动是毒 2020-11-27 13:31

I am busy converting a web application to MVC and have some information saved to Application variables used across multiple tenants/accounts to make things a bit more effici

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 14:02

    You can declare Application variables in Application_Start like this:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    
        var e = "Hello";
        Application["value"] = e;
    }
    

    To access this on controller write:

    string appVar = HttpContext.Application["value"] as string;
    

提交回复
热议问题