TextWriter只返回350行?

时间:2016-09-04 01:55:28

标签: c# asp.net-mvc textwriter

我有以下控制器和服务,它将数据返回给用户以填充Excel文件。在使用SQL Server Express的LocalHost中,它运行良好。

但是......从云环境运行时,它只能写350条记录。知道为什么它会在350处限制响应吗?

[HttpPost]
[ValidateAntiForgeryToken]
public void Index(ReportsViewModel vm)
{
    // additional code removed for brevity
    if (ModelState.IsValid)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=ILT & eLearning Registrations - " + DateTime.Now.ToShortDateString() + ".xls");
        Response.ContentType = "application/vnd.ms-excel";
        Response.ContentEncoding = System.Text.Encoding.Unicode;
        Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());

        ReportService reportService = new ReportService();

        if (vm.Report == "Registrations")
        {
            reportService.DownloadRegistrationsReport(vm, Response);
        }
    }

    ViewBag.Reports = "active";
}

public void DownloadRegistrationsReport(ReportsViewModel vm, HttpResponseBase Response)
{
    using (ApplicationDbContext db = new ApplicationDbContext())
    {
        var registrations = (from r in db.Registrations
                             where (vm.BusinessUnit == "All" || r.BusinessUnit.Equals(vm.BusinessUnit)) &&
                                   (vm.Region == "All" || r.Region.Equals(vm.Region)) &&
                                   (vm.DeliveryType == "All" || r.DeliveryType.Equals(vm.DeliveryType)) &&
                                   (vm.CustomerTypeName == "All" || r.CustomerTypeName.Equals(vm.CustomerTypeName)) &&
                                   r.EndDate >= vm.StartDate &&
                                   r.EndDate <= vm.EndDate
                             select new
                                  {
                                     RegistrationId = r.RegistrationId,
                                     ScheduleId = r.ScheduleId,
                                     CourseId = r.CourseId,
                                     RegistrationDate = r.RegistrationDate,
                                     // code removed for brevity
                                  }).ToList();

        WriteTsv(registrations, Response.Output);
        Response.End();
    }
}

public void WriteTsv<T>(IEnumerable<T> data, TextWriter output)
{
    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));

    foreach (PropertyDescriptor prop in props)
    {
         output.Write(prop.DisplayName); // header
         output.Write("\t");
    }

    output.WriteLine();

    foreach (T item in data)
    {
        foreach (PropertyDescriptor prop in props)
        {
            output.Write(prop.Converter.ConvertToString(
            prop.GetValue(item)));
            output.Write("\t");
        }

        output.WriteLine();
    }
}

0 个答案:

没有答案