Accessing HttpApplication.Application variables from a class

Posted by Young Ninja on Stack Overflow See other posts from Stack Overflow or by Young Ninja
Published on 2010-06-09T23:35:34Z Indexed on 2010/06/09 23:42 UTC
Read the original article Hit count: 188

Filed under:
|
|
|

I set up various global parameters in Global.asax, as such:

Application["PagePolicies"] = "~/Lab/Policies.aspx";
Application["PageShare"] = "/Share.aspx";
Application["FileSearchQueries"] = Server.MapPath("~/Resources/SearchQueries.xml");
...

I have no problem accessing these variables form .ascx.cs or .aspx.cs file -- ie. files that are part of the Web content. However, I can't seem to access 'Application' from basic class objects (ie. standalone .cs files). I read somewhere to use a slight variations in .cs files, as follows, but it always comes throws an exception when in use:

String file = (String)System.Web.HttpContext.Current.Application["FileSearchQueries"];

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET