I am writing code that allows users to remotely control IIS7. Under the hood, authorization rules are added c:\windows\system32\inetsrv\config\administration.configto the following configuration section:
system.webServer/management/authorization/authorizationRules
I am using Microsoft.Web.Administrationassembly and namespace with code similar to the following:
using Microsoft.Web.Management.Server;
...
ManagementAuthorization.Grant("MySiteUser, "My Web Site", false);
This code throws an exception if it is running in a 32-bit process, if it is built as 64-bit, it works fine:
System.Runtime.InteropServices.COMException was unhandled
Message = Filename: \\? \ C: \ Windows \ system32 \ inetsrv \ config \ administration.config
Error: The configuration section 'system.webServer / management / authorization' cannot be read because it is missing a section declaration`
However, other server management tasks performed using the assembly Microsoft.Web.Administrationand namespace work fine in a 32-bit process, for example:
using Microsoft.Web.Administration;
....
int iisNumber = 60000;
using (ServerManager serverManager = new ServerManager())
{
var site = serverManager.Sites.Where(s => s.Id == iisNumber).SingleOrDefault();
if (site != null)
{
site.Stop();
}
}
Both of these assemblies are displayed in the GAC and are pure MSIL (although there is a COM interaction layer to communicate directly with IIS7 control mechanisms).
The main configuration files applicationHost.configand administration.configare only for 64-bit editors (for example, notepad.exe or NotePad2.exe), and I suspect that's why my code can not be changed administration.configthroughMicrosoft.Web.Management
Why Microsoft.Web.Administrationdoes it allow me to read / modify applicationHost.configin a 32-bit process, but Microsoft.Web.Managementcan read / modify administration.configonly when it starts in a 64-bit process?
x64, 32- COM, . , 64- WCF ( ), .