ASHX 处理程序无法与网络外部的客户端正常工作



我有一个应用程序,供组织内外的人员使用。 此应用程序导出 Excel (.xlsx) 和 PDF 文件。 我在导出文件时遇到问题。 它适用于我的网络上的人,但我网络外的人收到"文件读取错误。 文件类型不受支持或文件已损坏",并且文件将只有 127 字节而不是正确的大小(通常约为 2 MB)。 我需要网络外部的人员能够成功下载和打开文件。

我还尝试运行针对每种特定文件类型定制的处理程序类,我尝试打开带有文件的目录以使"每个人"具有读取访问权限,我真的不确定如何解决这个问题。 Web 服务器正在运行 IIS 10。

public class fileExportHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string fileToExport = "";
        string fileName = "exportedFile";
        string fileType = "";
        System.Web.HttpRequest request = System.Web.HttpContext.Current.Request;
        if ((request.QueryString["fileToExport"] != null))
        {
            fileToExport = request.QueryString["fileToExport"].ToString();
            string[] fileParts = fileToExport.Split('.');
            fileType = fileParts[1];
            if ((request.QueryString["fileName"] != null))
            {
                fileName = request.QueryString["fileName"].ToString();
            }
        }
        fileToExport = @"E:WebsiteCascade" + fileToExport;
        //send the file to the browser
        System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
        Response.ClearHeaders();
        Response.Clear();
        Response.Buffer = true;
        string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        if(fileType == "pdf")
            contentType = "application/pdf";
        Response.ContentType = contentType;
        Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + fileType);
        Response.TransmitFile(fileToExport);
        Response.Flush();
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

搞清楚了。 这是一个网络问题,我的网络人员已将我移动到新服务器,组织外部的人员看到的是旧服务器,但内部人员看到了新版本。 我让他们让我组织外部的人看到新服务器,这解决了我的问题。