当前位置:编程学习 > C#/ASP.NET >>

c#程序 DirectoryEntry类的一个问题,大哥们帮帮忙啊!

DirectoryEntry de = new DirectoryEntry(@"IIS://" + this.MachineName + @"/W3SVC", this.LoginAccount, this.LoginPassword);

当this.MachineName为本机即localhost的时候能够正常连接。

当this.MachineName为远程机器的IP时,若账号密码错误,就报:拒绝访问。这个没问题。

但是当账号密码正确的时候,就报:RPC 服务器不可用。有没有哪位大神碰到过并解决过这个问题的啊?PS:远程机器的RPC服务已开启

小弟在此先谢过各位了! --------------------编程问答-------------------- --------------------编程问答-------------------- 哎。。。 --------------------编程问答-------------------- 先不要通过程序,直接在网上邻居中看看能不能打开这个目录,如果打不开共享,防火墙都看一下

如果再不行,RPC(Remote Procedure Call Protocol)——远程过程调用协议
看看远程的这个协议有没有
--------------------编程问答--------------------
防火墙关闭试试

--------------------编程问答--------------------         static void Main(string[] args)
        {
            string MachineName = "127.0.0.1";

            string LoginAccount = "username";

            string LoginPassword = "password";

            DirectoryEntry rootDirectory = new DirectoryEntry(@"IIS://" + MachineName + @"/W3SVC", LoginAccount, LoginPassword);
            int totalServerCount = 0;
            try
            {

                foreach (DirectoryEntry child in rootDirectory.Children)
                {
                    if (child.SchemaClassName == "IIsWebServer")
                    {
                        totalServerCount++;
                    }
                }
            }
            catch (Exception ex)
            {
                throw (new Exception("Can't connect to IIS Server " + MachineName + " : " + ex.Message));
            }

            Console.WriteLine(totalServerCount);



这是一段控制台测试程序,放入Program.cs的main方法中即可,需要引入System.DirectoryServices; --------------------编程问答-------------------- 麻烦哪位大大帮忙测试下啊,127.0.0.1肯定是可以的,换成远程就不行了。。。

VS需要用管理员权限运行才能调试的! --------------------编程问答-------------------- 防火墙关了还是不行,RPC已经开启了的。。。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,