I want to load my MVC 3 application settings into memory for better performance.
So far I can assign them in the global.asa.cs but I cannot access the variables in any controller. Any idea why?
Global.asa.cs Code
public class MvcApplication : System.Web.HttpApplication
{
public static string DBUserName = Properties.Settings.Default.DBUserName;
public static string DBPassword = Properties.Settings.Default.DBPassword;
HomeController code:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
_Authenticate(DBUserName , DBPassword );
You need to access them by specifying the class name in which they are declared:
MvcApplicationis the name of the class in this the two fields are declared.For this to work you need to declare the 2 fields as static: