Using Multiple Config files for a shared MVC Project
I have an MVC application that consists of a directory with all the necessary files to run except the css and master view. In IIS, I have several sites set up that all use the same directory, but then have virtual directories set up for each site's unique css and template. This works very well, although I am now wanting to have a separate config for each unique site (for basic settings like site id to query my db, etc). I created new virtual directories for each site and added a config.xml in each, added the following to my global.asax.cs file in the application start method:
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
//read in all the application variables from the config file on startup
XmlDocument Doc = new XmlDocument();
Doc.Load(Server.MapPath("/Config/Config.xml"));
XmlNodeList VarLst = Doc.DocumentElement.SelectNodes("//AppVars/*");
foreach (XmlNode VarNod in VarLst)
{
RecursiveDescent(VarNod, "");
}
string[] AppVars = new string[Application.Count];
AppVars = Application.AllKeys;
//How do I now use Application.AllKeys from a controller?
}
Now, I have my keys, but can't seem to figure out how to use them in a controller. Normally, if I was using the app settings in the web config an开发者_JS百科d wanted to set my siteId, I'd just use:
int siteId = Convert.ToInt16(WebConfigurationManager.AppSettings["SiteId"]);
but now I want to use
Application["SiteId"];
but it's not like a webforms code behind that inherits from the page class and I'm not getting the concept on how to get the Applications settings in an MVC controller.
As per this other question: Access "Application" object in ASP.Net MVC to store application wide variables
this.HttpContext.Application["SiteId"]
精彩评论