System.Net.Sockets.SocketExcep ... [英] System.Net.Sockets.SocketExcep...

查看:63
本文介绍了System.Net.Sockets.SocketExcep ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次在不同服务器上获取报告时出现跟踪错误我再次刷新网页报​​告正确显示。可能是什么原因?



I am getting followed error while first time get report on different server afterwards i refresh web page again report appearing properly.What can be cause?

System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.6.240.151:80







protected void Page_Load(object sender, EventArgs e)
{
    Response.Clear();
    try
    {
        if (Request.QueryString.Keys.Count == 0)
            Response.End();
        else
        {
            string uri = ConfigurationSettings.AppSettings["uri"] + Request.QueryString;
            WebRequest request = WebRequest.Create(uri);
            WebResponse responses = request.GetResponse();
            byte[] response = new System.Net.WebClient().DownloadData(uri);
            Response.ContentType = "application/pdf";
            Response.AppendHeader("Content-Disposition", responses.Headers.GetValues(2)[0]);
            Response.BinaryWrite(response);
            Response.Flush();
            Response.End(); 
        }
    }
    catch {
        throw exception;
    }
}







<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="uri" value="http://test.domain.com/report/?" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.net>
     <defaultProxy>
        <proxy proxyaddress = "http://10.6.240.151:80" bypassonlocal = "True" />
     </defaultProxy>
  </system.net>
</configuration>

推荐答案

请检查您拥有的代理地址是什么upplied是正确的

这是:

< defaultProxy>

< proxy proxyaddress =http://10.6.240.151:80 bypassonlocal =True/>

< / defaultProxy>





第二件事检查那个无论您使用哪个URL进行下载,都可以从执行此代码的机器访问。



Please check that whatever proxy address you had supplied is correct
Here it is:
<defaultProxy>
<proxy proxyaddress = "http://10.6.240.151:80" bypassonlocal = "True" />
</defaultProxy>


second thing check that whatever url you are using for downloading purpose it is accessible from the machine in which you are executing this code.

<pre lang="xml"><appSettings>
    <add key="uri" value="http://test.domain.com/report/?" />
  </appSettings>









u也可以尝试从命令行实用程序执行命令。 。



tracert [ ^ ]



来自您的机器,您可以查看以上网址是否可访问。





u can also try follwing command from command line utility...

tracert [^]

from your machine and you can check that above url is accessible or not.


我认为无论何时第一次请求报告。创建需要一些时间,但下次下载相同的报告时,后续请求不会创建。

您不应该在Page_Load上执行下载。您应该只显示一条消息请等待您的报告生成。并使用JSON和Custom Http Handler(在ASP.NET中实现HTTPHandler和HTTPModule [ ^ ])下载文件。您也可以设置5次尝试试用循环:



I think whenever you are requesting the report for first time. It takes time for creation, but next time onward that same report is getting downloaded, there is no creation for subsequent requests.
You should not perform download on Page_Load. You should simply display a message saying "Please wait while your report is getting generated." and use JSON and Custom Http Handler (Implementing HTTPHandler and HTTPModule in ASP.NET[^]) to download the file. You can also set up a 5 attempt trial loop like so:

// This code will be inside your custom HttpHandler.
private void DownloadFileAsync()
{
    int attempts = 0;
    int maxAttempts = 5;
    while(attempts < maxAttempts)
    {
        try
        {
            //Your download code
        }
        catch(SocketException socketEx)
        {
            attempts++;
            //Do your exception logging or throwing if required
        }
        catch(Exception ex)
        {
            //Do your exception logging or throwing if required
        }
    }
}


这篇关于System.Net.Sockets.SocketExcep ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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