日期:2014-05-17  浏览次数:20452 次

访问IIS的问题, 报"User credentials cannot be used for local connections" 100分回报!
想通过DirectoryEntry和ManagementScope 来对IIS进行操作。
代码如下
 public bool Connect()
  {
  if (_serverName == null)
  return false;
  try
  {
  _iisServer = new DirectoryEntry("IIS://" + _serverName + "/W3SVC/1");
  _target = _serverName;
  _connection = new ConnectionOptions();
  _connection.Username = @"myname";
  _connection.Password = "mypassword";
  _scope = new ManagementScope(new ManagementPath(@"\\" + _serverName + @"\root\MicrosoftIISv2"), _connection);
  _scope.Connect();
  }
  catch(Exception ex)
  {
  string msg = ex.Message;
  return false;
  }
  return IsConnected();
  }

结果报如上错误。User credentials cannot be used for local connections
请指教!!多谢

------解决方案--------------------
sf
------解决方案--------------------
关注
------解决方案--------------------
帮顶~
------解决方案--------------------
帮你顶
------解决方案--------------------
ding!