如何使用 System.DirectoryServices 访问不同域上的 Web 服务器

发布于 2024-12-05 04:47:42 字数 362 浏览 1 评论 0原文

我正在尝试编写一个简单的程序来列出 IIS 服务器的虚拟目录,该服务器与我的本地计算机位于不同的域中。创建根 DirectoryEntry 对象时,我尝试传递带有域限定符的凭据,如下所示:

DirectoryEntry entry = new DirectoryEntry("IIS://myremoteserver/W3SVC/1/Root", "mydomain\\myusername", "mypassword");

但是,我收到“访问被拒绝”异常。这是正确的方法吗?我发现的所有代码示例都只能访问本地网络服务器。 我在本地运行 WinXP SP3,并尝试连接到运行 IIS 版本 6.0 的 Win2003 R2(64 位)服务器。

I am trying to write a simple program to list the virtual directories of an IIS server, which is on a different domain than my local machine. When creating the root DirectoryEntry object, I tried to pass in the credentials with a domain qualifier, like this:

DirectoryEntry entry = new DirectoryEntry("IIS://myremoteserver/W3SVC/1/Root", "mydomain\\myusername", "mypassword");

I get an "Access is Denied" exception, however. Is this the right way to do this? All the code examples I've found only access the local web server.
I running WinXP SP3 locally, and trying to connect to a Win2003 R2 (64-bit) server running IIS version 6.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最笨的告白 2024-12-12 04:47:42

我决定使用 System.Management< /a> 类来执行此操作,当我在登录中使用域限定符时,它会起作用:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace MyProgram
{
    class Program
    {

        static void Main(string[] args)
        {
            ConnectionOptions options = new ConnectionOptions();
            options.Authentication = AuthenticationLevel.PacketPrivacy;
            options.Username = "somedomain\\username";
            options.Password = "password";
            ManagementPath path = new ManagementPath();
            path.Server = "someserver";
            path.NamespacePath = "root/MicrosoftIISv2";
            ManagementScope scope = new ManagementScope(path, options);

            string Query = "select * from IIsWebVirtualDirSetting";
            using (ManagementObjectSearcher search = new ManagementObjectSearcher(scope, new ObjectQuery(Query)))
            {
                ManagementObjectCollection results = search.Get();
                foreach (ManagementObject obj in results)
                {
                    Console.WriteLine(obj.Properties["Name"].Value);
                }                
            }          
            Console.ReadLine();
        }
    }
}

I decided to use the System.Management classes to do this instead, which works when I use a domain qualifier in the login:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace MyProgram
{
    class Program
    {

        static void Main(string[] args)
        {
            ConnectionOptions options = new ConnectionOptions();
            options.Authentication = AuthenticationLevel.PacketPrivacy;
            options.Username = "somedomain\\username";
            options.Password = "password";
            ManagementPath path = new ManagementPath();
            path.Server = "someserver";
            path.NamespacePath = "root/MicrosoftIISv2";
            ManagementScope scope = new ManagementScope(path, options);

            string Query = "select * from IIsWebVirtualDirSetting";
            using (ManagementObjectSearcher search = new ManagementObjectSearcher(scope, new ObjectQuery(Query)))
            {
                ManagementObjectCollection results = search.Get();
                foreach (ManagementObject obj in results)
                {
                    Console.WriteLine(obj.Properties["Name"].Value);
                }                
            }          
            Console.ReadLine();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文