I have and Windows Service and a couple of Web Applications all using the same assemblies.
When a call is made to one method in particular in one of these common assemblies I want to either pass it the current applications name or path or have the method itself determine what called it.
The reason being I have some System.Configuration stuff goin on within the method and if it's a Windows Service that called the method I want it to use the
and if it's a website I want it to use theCode:System.Configuration.ConfigurationManager.OpenExeConfiguration(appnameandpath);
How can I achieve this?Code:System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( "/websitename");
The .config files contain some Custom Sections which I wish to access, I have no problem getting to the Web Applications but determining the Windows Service path and name and opening its app.config is proving difficult.
Code:public static string GetMessageString(string server, string messagename) { string serverName = "/"; string message = string.Empty; System.Configuration.Configuration configuration; MessageSection section; //Try the current Applications .config file first, if it exists, e.g. the ManagementServer.config try { configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(server); section = (MessageSection)configuration.GetSection("messagegroup/messagesection"); message = section.GetMessage(messagename); } catch//if the exe's config fails then try the Web application web.config { configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( "/" + server); section = (MessageSection)configuration.GetSection("messagegroup/messagesection"); message = section.GetMessage(messagename); } return message; }




Reply With Quote