我在 silverlight 目录中有 Excel 导出功能。
用户右键单击目录,这将触发通过浏览器的下载。
public static void ExportValues(CatalogData data)
{
var excelData = new ExcelData
{
Sheets = new[] { data }
};
string serializedData = excelData.Serialize();
HtmlPage.Window.Invoke("exportToExcel", serializedData);
}
这是 JavaScript 调用
function exportToExcel(serializedData) {
var formId = "exportToExcelForm";
var inputId = "SerializedExcelData";
var form = document.getElementById(formId),
input;
if (form == null) {
form = document.createElement("form");
form.setAttribute("id", formId);
form.setAttribute("method", "POST");
form.setAttribute("action", "../api/excel");
form.style.visibility = "hidden";
form.style.height = "0px";
form.style.width = "0px";
form.style.borderWidth = "0px";
document.body.appendChild(form);
input = document.createElement("input");
input.setAttribute("id", inputId);
input.setAttribute("type", "hidden");
input.setAttribute("name", inputId);
form.appendChild(input);
} else {
input = document.getElementById(inputId);
}
input.setAttribute("value", serializedData);
form.submit();
input.setAttribute("value", "");
}`
[HttpPost]
public static HttpResponseMessage GenerateExcel(ExcelDataWrapper wrapper)
{
ExcelData data = wrapper.Unwrap();
var content = new StreamContent(ExcelCreator.Create(data));
var clientDateTime = ExcelCreator.ClientDateTime;
var fileName = "test.xlsx";
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName };
content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return new HttpResponseMessage(HttpStatusCode.OK) { Content = content };
}
问题是,当部署到 IIS 服务器时,我收到错误 HTTP/1.1 415 不支持的媒体类型,请参阅 Fiddler
This code is running perfectly on my machine (Localhost)
无法找到这里出了什么问题