【问题标题】:Proxy does not accept offered credentials. C# remoting代理不接受提供的凭据。 C# 远程处理
【发布时间】:2015-10-19 12:33:07
【问题描述】:

代理服务器出现问题,它不接受我的应用程序提供的身份验证详细信息。这是我正在做的事情:

    private bool DoLoginTest(WebProxy wp = null)
    {
        if(MMremotingClient.LoginWCP(wp) == AdminNetworkFlags.CLIENTPOS)
        {
            FL.Log("Test licensing server connection REM finished");
            FL.Log("Connection could be established successfully");

            MMremotingClient.DoTask(BitConverter.GetBytes((int)AdminNetworkFlags.CLIENTEND), "Nothing");
            MMremotingClient.DisableFLogging();
            Invoke(txtDelegate, " finished\r\n");
            return true;
        }
        else
        {
            FL.Log("Test server connection failed!");
            FL.Log("NoTask");
            Invoke(txtDelegate, " failed\r\n");
            Invoke(MBDelegate, "Could not reach the licencing server. Please make sure that no firewall is blocking port 80, or that your computer is allowed to access the internet.");
            return false;
        }
    }

在一系列测试中,我尝试使用旧的远程协议连接到服务器(无法升级到 WCF atm)。如果 DoLoginTest 方法失败,用户将看到一个小表单,他可以在其中输入注入到 HTTPClientChannel 对象中的代理详细信息。然后再次尝试连接到服务器。

    public static AdminNetworkFlags LoginWCP(WebProxy wProx = null)
    {
        FileLogger.Log("MMLC: LoginWCP");
        Register(wProx);
        return Login();
    }

    private static void Register(WebProxy iwp = null)
    {
        FileLogger.Log("MMLC: Register");
        try
        {
            IDictionary props = new Hashtable();

            if(iwp == null)
            {
                props["useDefaultCredentials"] = true;
            }
            else
            {
                NetworkCredential nc = (NetworkCredential)iwp.Credentials;
                if(nc != null)
                {
                    props["domain"] = nc.Domain ?? null;
                    props["password"] = nc.Password;
                    props["username"] = nc.UserName;
                    props["useDefaultCredentials"] = false;
                }
                else
                {
                    props["domain"] = null;
                    props["password"] = "1234";
                    props["username"] = "u.name";
                    props["useDefaultCredentials"] = false;
                }
            }
            ServicePointManager.Expect100Continue = false;
            HttpChan = new HttpClientChannel(props, new BinaryClientFormatterSinkProvider());
            SetChannelProxy(HttpChan, iwp ?? WebRequest.GetSystemWebProxy());
            FileLogger.Log("MMLC: RegChannel");
            ChannelServices.RegisterChannel(HttpChan, true);
            RemoteObject = (IRemObject)Activator.GetObject(typeof(IRemObject), "http://someAdress:80/IRemObject");
            FileLogger.Log("MMLC: connected");
        }
        catch(Exception x)
        {
            Trace.WriteLine("Error connecting to remote server, reason: " + x.Message);
            RemoteObject = null;
        }
    }

    private static void SetChannelProxy(HttpClientChannel channel, IWebProxy proxy)
    {
        FieldInfo proxyObjectFieldInfo = typeof(HttpClientChannel).GetField("_proxyObject", BindingFlags.Instance | BindingFlags.NonPublic);
        proxyObjectFieldInfo.SetValue(channel, proxy);
    } 

这是询问用户代理详细信息的表单。如果用户点击其上的“确定”按钮结束它,则设置定义的代理属性。然后将该属性传递给 LoginWCP() 函数。

    private void button1_Click(object sender, EventArgs e)
    {
        definedProxy = new WebProxy(txtAdress.Text, decimal.ToInt32(nudPort.Value));
        Address = txtAdress.Text;
        Port = decimal.ToInt32(nudPort.Value);
        NetworkCredential nc = new NetworkCredential()
        {
            Domain = string.IsNullOrWhiteSpace(txtDomain.Text) ? null : txtDomain.Text,
            UserName = txtName.Text,
            Password = txtPassword.Text
        };
        definedProxy.Credentials = nc;
        DialogResult = System.Windows.Forms.DialogResult.OK;
        Close();
    }

到目前为止,这一切正常,但现在我在 Active Directory 环境中拥有了第一个使用代理的用户。由于我缺少 AD,我无法在其中测试应用程序。所以我问你,我的申请有什么问题吗?我需要检查用户 ipnut 的东西吗? Expect100Continue = false做坏事了吗?

【问题讨论】:

  • 我讨厌颠簸,但我只是需要,因为这个问题又发生了。

标签: c# proxy remoting


【解决方案1】:

所以,这件事又发生了,但这一次是可以解决的。首先,我必须说出让我很难受的罪魁祸首。 ZScaler。该软件套件围绕阻止和嗅探来自外部和内部的连接而构建,似乎只允许连接到地址,而不是直接 IP。到目前为止,我的应用程序直接连接到 IP,而不是真实地址。稍后进行一些更改,我的服务器现在可以通过地址浏览,并且应用程序由 ZScaler 的代理通过。

【讨论】:

    猜你喜欢
    • 2013-08-05
    • 2013-08-19
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多