ASP - 在本地主机中运行 - 无法访问互联网

发布于 2024-08-19 15:56:43 字数 599 浏览 5 评论 0原文

我有一个 ASP MVC 控制器操作。 我正在尝试发出 Web 请求,

public ActionResult Index()
{
   WebRequest request = HttpWebRequest.Create("http://www.example.com");
   WebResponse response = request.GetResponse();
   string str =  response.ToString();
}`

但出现“发生 WebException”,无法解析远程名称:“www.example.com”

如果我启动 Fiddler,则 Web 请求有效。

我尝试添加:

 <system.net>
 <defaultProxy>
   <proxy usesystemdefault ="True" bypassonlocal="True"  />
 </defaultProxy>

到Web.config(有或没有htebypassonlocal),它仍然不起作用。

有什么建议吗?

I have an ASP MVC controller action.
I'm trying to make a web request

public ActionResult Index()
{
   WebRequest request = HttpWebRequest.Create("http://www.example.com");
   WebResponse response = request.GetResponse();
   string str =  response.ToString();
}`

I get a "WebException occured" the remote name could not be resolved: 'www.example.com'

If I start Fiddler, then the webrequest works.

I tried adding:

 <system.net>
 <defaultProxy>
   <proxy usesystemdefault ="True" bypassonlocal="True"  />
 </defaultProxy>

to Web.config (with and without hte bypassonlocal) and it still doesn't work.

Any suggestions?

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

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

发布评论

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

评论(1

终难遇 2024-08-26 15:56:43

尝试显式指定代理服务器:

<system.net>
    <defaultProxy>
        <proxy proxyaddress="http://proxy.yourcompany.com:80" />
    </defaultProxy>
</system.net>

您还可以通过编程方式设置代理:

request.Proxy = new WebProxy("http://proxy.yourcompany.com:80", true);

当您将 usesystemdefault 设置为 true 时,应用程序将使用 Internet 选项<中定义的代理/代码> 对话框。当您在 IIS 中部署应用程序时,它通常在权限非常有限的网络服务帐户下执行,它甚至没有任何 GUI 会话,因此无法推断代理服务器。

Try specifying the proxy server explicitly:

<system.net>
    <defaultProxy>
        <proxy proxyaddress="http://proxy.yourcompany.com:80" />
    </defaultProxy>
</system.net>

You could also set the proxy programatically:

request.Proxy = new WebProxy("http://proxy.yourcompany.com:80", true);

When you set usesystemdefault to true, the application uses the proxy defined in the Internet Options dialog box. When you deploy your application in IIS it usually executes under the Network Service account which has very limited privileges, it doesn't even have any GUI session so it cannot infer the proxy server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文