I am using a generic handler to download csv/excel files. It was working fine until yesterday. Today suddenly it stopped working on deployment on IIS 7.5 (though he same code works well in visual studio debugging mode). Here is my code:
ASPX: This is a content page
<input type="button" class="btn-primary" id="btnDownload" title="Download" value="Download" onclick='return downloadReport(this);' data-toggle="modal" data-target="#myModal" navurl='<%: ResolveUrl("~/Handlers/DownloadData.ashx") %>' />
JS:
function downloadReport(btn) {
//I am using a kendoUI combo box and kendo js + also using bootstrap for design & modal popups & also i have applied bundling to kendo & bootstrap files. They seem to be working fine without any conflicts as all their api's are working.
var $mod = $("#masterModal");
$mod.modal('show');
//window.location = "Handlers/DownloadData.ashx?rtp=" + combobox.val();
window.location.href = $(btn).attr("navurl") + "?rtp=" + combobox.val();
setTimeout(function () {
$mod.modal("hide");
}, 2000);
return false;
}
Master Page:
I am including the js file containing the above method just before end of body tag.
<script src='<%: ResolveUrl("~/Scripts/DataUploader.js") %>'></script>
</body>
</html>
Handler: In handler Process Request Method
HttpResponse response = this._context.Response;
HRReportData hrData = new HRReportData(ConfigMaster.DbProvider, ConfigMaster.ConnectionString, ConfigMaster.DBSchemaName);
ReportDataManager rdm = null;
ExcelPackage xlPackage = null;
try
{
rdm = new ReportDataManager();
DataSet ds = rdm.GetReportData(hrData, report_Type);
if (ds != null && ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
xlPackage = new ExcelPackage();
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add(report_Type.ToString());
worksheet.Cells["A1"].LoadFromDataTable(ds.Tables[0], true, TableStyles.Light1);
response.ClearHeaders();
response.ClearContent();
response.Clear();
response.ContentType = "application/octet-stream";
response.AppendHeader("content-disposition", "attachment; filename=" + report_Type.ToString() + ".xlsx");
xlPackage.SaveAs(response.OutputStream);
response.Flush();
//response.Close();
//response.End();
}
}
}
catch (Exception ex)
{
//LogError.MethodLevelError(Convert.ToString(Session["Username"]), ex);
if (!(ex is System.Threading.ThreadAbortException))
{
//Other error handling code here
}
}
finally
{
if (xlPackage != null)
{
xlPackage.Dispose();
xlPackage.Dispose();
}
}
Bundle config:
bundles.Add(new ScriptBundle("~/Kendo/kendo").Include(
"~/Scripts/jquery-1.11.3.min.js",
"~/Kendo/js/kendo.all.min.js"
// "~/Scripts/DataUploader.js"
));
bundles.Add(new ScriptBundle("~/bootstrap/bootstrap").Include(
"~/bootstrap/js/holder.js",
"~/bootstrap/js/ie10-viewport-bug-workaround.js",
"~/bootstrap/js/ie-emulation-modes-warning.js",
"~/bootstrap/js/bootstrap.min.js"
));
All above code works well in debugging mode and was working well in deployment mode as well. Don't know what has changed that it suddenly stopped working and I am unable to find out any reasons :(
Behaviour on deployment: Instead of staying on same page and downloading file it navigates to Handler and a blank screen is displayed. No file is downloaded.
Behaviour in debuuging mode OR when run using vs2012 express: It stays on same page and downloads the file as expected.
Somebody please help me on this.
Aucun commentaire:
Enregistrer un commentaire