在C#中显示代理验证对话框 [英] Display the proxy authentication dialog in C#

查看:110
本文介绍了在C#中显示代理验证对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问互联网我在一个需要认证的代理之后。我知道把网络证书传递给代理很简单:

  FtpWebRequest request = FtpWebRequest.Create(
新的Uri(ftp://upload.myserver.com)作为FtpWebRequest;

NetworkCredential凭证=新的NetworkCredential(用户名,密码);
request.Credentials =凭证;

这是有效的!



我也尝试使用 CredentialCache.DefaultNetworkCredentials ,但这不起作用。我想避免将用户名和密码存储在任何地方(代码,数据库,配置文件)。



我认为最简单的方法是使用当我使用Internet Explorer访问互联网时显示的对话框。有没有人知道如何提高这个对话框?



http:// services.arcgisonline .com / arcgisexplorer500 / help / proxy_connect_to_on_browser_request.png



编辑

这个任务的目标是通过FTP上传文件。最后,我发现没有必要为FTP请求设置代理,因为.NET框架不允许通过HTTP代理进行FTP操作。但是你必须明确地将代理属性设置为空。

  FtpWebRequest request = FtpWebRequest.Create(
new Uri ftp://upload.myserver.com)为FtpWebRequest;

NetworkCredential凭证= new NetworkCredential(username,password);
request.Credentials =凭证;
request.Proxy = null;

这就是它!

解决方案

首先,id说这不是IE对话框,它应该是一个buildin系统对话框。 b进一步,如果你调用它,你仍然需要访问输入的值并在你的代码中使用这个对话框,这个对话框只是一个输入窗口,它不会让你的应用程序访问代理/互联网!同时所有的错误处理错误,凭证等)必须由您自己完成。

我认为这可能更容易,检查是否需要代理(使用Windows注册表,wmi等),并弹出一个自定义表单你可以不容易访问和重用这些值。


to access the internet I am behind a proxy that requires authentication. I know it's quite simple to pass the network credentials to the proxy like this:

FtpWebRequest request = FtpWebRequest.Create(
                        new Uri("ftp://upload.myserver.com") as FtpWebRequest;

NetworkCredential credentials = new NetworkCredential("username", "password");
request.Credentials = credentials;

This works!

I also tried to use CredentialCache.DefaultNetworkCredentials but that doesn't work. I want to avoid storing user name and password anywhere (code, database, config file).

I thought the easiest way would be to use the same dialog that is displayed when I access the internet using Internet Explorer. Does anybody knows how to raise this dialog?

http://services.arcgisonline.com/arcgisexplorer500/help/proxy_connect_to_on_browser_request.png

EDIT

The goal of this task was to upload a file via FTP. Finally I found out that it is not necessary to set a proxy for FTP requests because .NET framework does not allow FTP operation through HTTP proxies. But you have to set the proxy property explicitly to null.

FtpWebRequest request = FtpWebRequest.Create(
                        new Uri("ftp://upload.myserver.com") as FtpWebRequest;

NetworkCredential credentials = new NetworkCredential("username", "password");
request.Credentials = credentials;
request.Proxy = null;

Thats it!

解决方案

First of all, id say that this is not an IE dialog. It should be a buildin system dialog.
Further if you invoke it, you still will need to access the entered values and use those in your code. That dialog is just an input window, it won't give your application access to the proxy/internet! Also all error handling (wrong, credentials, etc) have to be done by yourself.
I think it might be easier, to check if a proxy is required (using windows registry, wmi, etc) and pop up a custom form where you can easisly access and reuse the values.

这篇关于在C#中显示代理验证对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆