1

I have a web application and I need to access some configuration information in a Windows service running on the same server. What I have works locally but not when deployed to server.

I understand the application runs using aspnet.exe worker process running under ASPNET account. In authentication section of IIS, I disabled anonymous authentication and enabled impersonation and Windows authentication. I had application pool running under application pool identity but tried network service, just in case, but didn't help.

This is the partial code, up to the point it throws exception:

using (ManagementObject wmiService = new ManagementObject("Win32_Service.Name='" + ServiceName + "'"))
{
    try
    {
        wmiService.Get();
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);      // Throws "Access Denied" error
    }
    string ServiceExePath = wmiService["PathName"].ToString();
    List<char> invalidPathChars = Path.GetInvalidPathChars().ToList();
    invalidPathChars.ForEach(c => ServiceExePath = ServiceExePath.Replace(c.ToString(), String.Empty));
    System.Configuration.Configuration config;

    try
    {
        config = ConfigurationManager.OpenExeConfiguration(ServiceExePath); 
        List<string> lsIP_Port = config.AppSettings.Settings["TcpServerListeners"].Value.Split(',').ToList();

    }
    ....
}
NoBullMan
  • 2,032
  • 5
  • 40
  • 93

0 Answers0