我正在尝试使用IIS
远程更改C#
应用程序池标识(用户)并出现错误
System.Runtime.InteropServices.COMException(0x800706BA):RPC服务器不可用。
如果我允许来自远程计算机上所有服务的所有RPC
动态端口(在49152到65535范围内)都来自防火墙,则我可以正确执行此操作。
我只想知道远程系统用来完成该过程的确切服务或进程名称,以便只允许该服务的端口使用。
public static bool ChangeAppPoolUser(string ip, string machineName, string username, string password, string applicationPoolName)
{
try
{
var metabasePath = "IIS://" + ip + "/W3SVC/AppPools";
// Get list of appPools at specified metabasePath location
using (DirectoryEntry appPools = new DirectoryEntry(metabasePath, username, password))
{
if(appPools==null)
{
Helper.PrepareDebugLog("appPools is null");
}
Helper.PrepareDebugLog("metabasePath:" + metabasePath + " username:" + username + " password:" + password);
// From the list of appPools, Search and get the appPool
using (DirectoryEntry AppPool = appPools.Children.Find(applicationPoolName, "IIsApplicationPool"))
{
Helper.PrepareDebugLog("in");
if (AppPool != null)
{
AppPool.InvokeSet("AppPoolIdentityType", new Object[] { 3 });
// Configure username for the AppPool with above specified username
AppPool.InvokeSet("WAMUserName", new Object[] { Environment.UserDomainName + "\\" + Environment.UserName });
// Configure password for the AppPool with above specified password
AppPool.InvokeSet("WAMUserPass", new Object[] { CommonProgramVariables.localPassword });
// Write above settings to IIS metabase
AppPool.Invoke("SetInfo", null);
// Commit the above configuration changes that are written to metabase
AppPool.CommitChanges();
return true;
}
}
}
}
catch (Exception e)
{
Helper.PrepareLogWithTimstamp("EXCEPTION WHILE CHNAGE USER: Parameter USED machineName:" + machineName + " username:" + username + " password:" + password + " applicationPoolName:" + applicationPoolName + " LocalPassword:" + CommonProgramVariables.localPassword + " Local User:" + Environment.UserDomainName + "\\" + Environment.UserName);
Helper.PrepareLog("EXCEPTION:", e);
}
return false;
}
预期:AppPool用户应更改为远程计算机AppPool。
实际结果:
System.Runtime.InteropServices.COMException(0x800706BA):RPC服务器不可用。