1
我想將我的MVC 3應用程序設置加載到內存中以獲得更好的性能。訪問控制器中的Global.asa.cs變量
到目前爲止,我可以在global.asa.cs中指定它們,但我無法訪問任何控制器中的變量。任何想法爲什麼?
Global.asa.cs代碼
public class MvcApplication : System.Web.HttpApplication
{
public static string DBUserName = Properties.Settings.Default.DBUserName;
public static string DBPassword = Properties.Settings.Default.DBPassword;
HomeController的代碼:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
_Authenticate(DBUserName , DBPassword);
我收到以下錯誤:一個對象引用需要非靜態字段,方法或屬性 – MataHari
不好意思啊,您需要將這些字段聲明爲靜態。我會更新我的答案。 –
你大夥....... – MataHari