I have an excel export function in a silverlight directory. The user will right-click on the directory, and this will lead to a download through the browser.
public static void ExportValues(CatalogData data)
{
var excelData = new ExcelData
{
Sheets = new[] { data }
};
string serializedData = excelData.Serialize();
HtmlPage.Window.Invoke("exportToExcel", serializedData);
}
Here is the javascript call
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 };
}
The problem occurs when deploying to the IIS server. I get HTTP / 1.1 error 415 Unsupported media type, see Fiddler

This code works fine on my machine (Localhost) 
It is impossible to find what is wrong here.
source
share