C#导出Excel文件后重定向过多

时间:2019-01-31 17:19:42

标签: c#

我不得不将数据从数据库导出到Excel中。

它正在运行,但是我们将应用程序移至了云服务器,但现在它不适用于大型Excel。 (30万个lignes不起作用,但15万个还可以)。

我收到下一个错误“ TOO_MANY_REDIRECTS”,但通常会打开一个流行音乐供下载。

我尝试在web.config中放入“ <httpRuntime requestValidationMode="2.0" executionTimeout="860"/>”,但仍然有相同的错误。

这是我下载此函数所调用的函数:

   public override void ExecuteResult(ControllerContext context)


        context.HttpContext.Response.ClearContent();
        context.HttpContext.Response.Clear();
        context.HttpContext.Response.Buffer = true;
        context.HttpContext.Response.Charset = "";
        // Add timestamp to filename
        string stamp = DateTime.Now.ToString("HHmmss");

        using (MemoryStream MyMemoryStream = new MemoryStream())
        {
            context.HttpContext.Response.AddHeader("content-disposition", "attachment;filename= ReportMe_Contacts_" + stamp + ".xlsx");
            context.HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

            workBook.SaveAs(MyMemoryStream);
            MyMemoryStream.WriteTo(context.HttpContext.Response.OutputStream);
            context.HttpContext.Response.Flush();
            context.HttpContext.Response.End();
        }
    }

你能帮我吗?

0 个答案:

没有答案