ASP - 在本地主机中运行 - 无法访问互联网
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试显式指定代理服务器:
您还可以通过编程方式设置代理:
当您将
usesystemdefault
设置为true
时,应用程序将使用Internet 选项<中定义的代理/代码> 对话框。当您在 IIS 中部署应用程序时,它通常在权限非常有限的网络服务帐户下执行,它甚至没有任何 GUI 会话,因此无法推断代理服务器。
Try specifying the proxy server explicitly:
You could also set the proxy programatically:
When you set
usesystemdefault
totrue
, the application uses the proxy defined in theInternet Options
dialog box. When you deploy your application in IIS it usually executes under theNetwork Service
account which has very limited privileges, it doesn't even have any GUI session so it cannot infer the proxy server.