Уточнение вопроса с меньшим количеством неизвестных. В случае успеха в вызове ajax я делаю перенаправление следующим образом.Моя проблема в том, что функция Controller никогда не срабатывает (я ставлю логирование и точки останова)
ПРИМЕЧАНИЕ. Обратите внимание, что это работает нормально, когда я запускаю приложение локально, но не при развертывании на сервере приложений.Я получаю сообщение об ошибке, которое указано в исходном сообщении ниже.
Код AJAX:
$(document).ready(function () {
$('#777').on('click', function () {
$.ajax({
type: "POST",
url: "Report/createFile",
dataType:"json",
success: function (data) {
var response = data;
alert("OK");
alert(response.FileGuid);
alert(response.FileName);
if (response != null &&
response.FileGuid != null &&
response.FileName != null) {
alert("Ready to redirect...");
window.location = '/Report/Download?fileGuid=' +
response.FileGuid + '&filename=' +
response.FileName;
}
else {
alert("Error downloading file");
}
},
error: function (data) {
alert("Report Generation Failed.");
},
});
});
});
Контроллер C #:
[HttpPost]
public ActionResult createFile()
{
// Some processing...
// returning the JSON object
return new JsonResult()
{
Data = new { FileGuid = handle, FileName =
"TestReportOutput.xlsx" }
};
}
[HttpGet]
public ActionResult Download(string fileGuid, string fileName)
{
// !! This code is never reached even though Ajax success
// !! function is executed after return from createFile() function
}
Old post:
I am downloading a file through a C# and ajax web application.
I used the following for reference:
https://stackoverflow.com/questions/16670209/download-excel-file-via-ajax-mvc
CSL's provided approach worked very well for me. However, once I published the app to a test server, the download fails with resource not found (404 error). It is looking for the created file in the physical path c:\inetpub\wwwwroot\Report\Download\TestReportOutput.xlsx and cannot find it.
i never had to create this physical path when running locally so not sure what I missed.
Running the app locally is completely fine with no issues.
This is the error message I get
Detailed Error Information
+ Module IIS Web Core
+ Notification MapRequestHandler
+ Handler StaticFile
+ Error Code 0x80070002
+ Requested URL http://localhost:80/Report/Download?fileGuid=04d40144-db9b-4b96-88c0-0ccb1a080c8c&filename=TestReportOutput.xlsx
+ Physical Path C:\inetpub\wwwroot\Report\Download
+ Logon Method Negotiate
I am not familiar with intricacies of server deployment so would appreciate any assistance or tips.