Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
捕获远程主机关闭的连接c#_C#_Asp.net_Model View Controller_Ashx - Fatal编程技术网

捕获远程主机关闭的连接c#

捕获远程主机关闭的连接c#,c#,asp.net,model-view-controller,ashx,C#,Asp.net,Model View Controller,Ashx,我在捕捉错误时遇到了问题 远程主机关闭了连接 在生产服务器上,但它正在我的本地计算机上工作。我的代码是这样的 try { SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid, guestEmail, couponCode, albumId, trackId, "Downloading"); List<faeTrackInfoDetail> result = SqlDataSource_Track.getTrackInfo

我在捕捉错误时遇到了问题

远程主机关闭了连接

在生产服务器上,但它正在我的本地计算机上工作。我的代码是这样的

try
{
    SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid, guestEmail, couponCode, albumId, trackId, "Downloading");
    List<faeTrackInfoDetail> result = SqlDataSource_Track.getTrackInfoDetail(trackId);
            faeTrackInfoDetail item = result.First();
    catalogueId = item.CatalogueID;
    filename = item.DiscNo.ToString() + "." + item.TrackNo.ToString() + " - " + CleanFileName(item.TrackTitle) + "." + mediaType;
    urlPath = "mydomain.com/Download/DownloadAudioTrack.ashx?id=" + catalogueId + "&trackid=" + trackId + "&ext=" + mediaType;
    context.Response.ClearContent();
    context.Response.ClearHeaders();
    if (mediaType != "mp3")
    {
       context.Response.ContentType = "application/octet-stream";
    }
    else
    {
       context.Response.ContentType = "application/mpeg";
    }
    context.Response.AppendHeader("Content-Disposition", "inline; filename=" + (char)(34) + filename + (char)(34));
    context.Response.BufferOutput = false;
    using (var wc = new WebClient())
    {
        using (var download = wc.OpenRead(urlPath))
        {
            using (var respStream = context.Response.OutputStream)
            {
                download.CopyTo(respStream);

                SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid, guestEmail, couponCode, albumId, trackId, "Downloaded");
            }
        }
    }
}
catch (Exception ex)
{
    string exceptionMessage = ex.Message;
    if (exceptionMessage.ToLower().Contains("the remote host closed the connection."))
    {
        // Download Cancelled!
        SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid, guestEmail, couponCode, albumId, trackId, "Cancelled");
    }
    else
    {
        // Download Error!
        SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid, guestEmail, couponCode, albumId, trackId, "Error");
    }
}
试试看
{
SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid、guestEmail、couponCode、albumId、trackId,“下载”);
列表结果=SqlDataSource\u Track.getTrackInfoDetail(trackId);
faeTrackInfoDetail item=result.First();
CatalogEID=item.CatalogEID;
filename=item.DiscNo.ToString()+“+”+item.TrackNo.ToString()+“-”+CleanFileName(item.TrackTitle)+“+”+mediaType;
urlPath=“mydomain.com/Download/DownloadAudioTrack.ashx?id=“+catalogeId+”&trackid=“+trackid+”&ext=“+mediaType;
context.Response.ClearContent();
context.Response.ClearHeaders();
如果(媒体类型!=“mp3”)
{
context.Response.ContentType=“应用程序/八位字节流”;
}
其他的
{
context.Response.ContentType=“应用程序/mpeg”;
}
AppendHeader(“内容处置”,“内联;文件名=“+(字符)(34)+文件名+(字符)(34));
context.Response.BufferOutput=false;
使用(var wc=new WebClient())
{
使用(var download=wc.OpenRead(urlPath))
{
使用(var respStream=context.Response.OutputStream)
{
下载.CopyTo(respStream);
SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid、guestEmail、couponCode、albumId、trackId,“下载”);
}
}
}
}
捕获(例外情况除外)
{
字符串异常消息=例如消息;
if(exceptionMessage.ToLower()包含(“远程主机关闭了连接”))
{
//下载取消!
SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid、guestEmail、couponCode、albumId、trackId,“已取消”);
}
其他的
{
//下载错误!
SqlDataSource_Gift.saveGiftDownloadLogs(guestGuid、guestEmail、couponCode、albumId、trackId,“错误”);
}
}
我需要知道用户何时取消下载并将其记录到数据库。现在,当代码部署到prod server时,它不起作用,但在调试时起作用


IIS
中是否有需要检查的设置。提前感谢。

您是否在本地使用IISExpress或真实的IIS实例?在生产服务器上,可能安装了另一个框架,然后是英文框架?永远不要对本地化字符串做出决定。嗨,Jeroen,我正在IISExpress上运行它。它还在我的本地计算机上运行IIS。我不确定生产服务器中的设置。你在本地计算机上使用IISExpress还是真实的IIS实例?在生产服务器上,可能安装了另一个框架,然后是英文框架?永远不要对本地化字符串做出决定。嗨,Jeroen,我正在IISExpress上运行它。它也在我本地的IIS上运行。我不确定生产服务器中的设置。