Browse to file upload fails on Azure website (small file)

半腔热情 提交于 2019-12-11 20:40:13

问题


I can upload a .xlsx file on my website running locally but it 404's after publishing to Azure. ASP.Net/webforms; C#;

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

Any ideas would be appreciated.

if (!this.FileUpload1.FileName.Equals("ActionFile.xlsx"))
{
    this.tbxAdminStatus.Text = "Missing input file ActionFile.xlsx";
    return;
}
else
{
    // Upload file
    fileLoc = Server.MapPath("~/Upload/" + his.FileUpload1.PostedFile.FileName);

    try
    {
         this.FileUpload1.PostedFile.SaveAs(fileLoc);
         this.tbxAdminStatus.Text = "File ActionFile.xlsx Uploaded";
    }
    catch (Exception ex)
    {
        Response.Write("Error: " + ex.Message);
    }
}

回答1:


Are you saying that when you browse to .xslx file directly from browser then you get the 404 error even if the file exists??? For 404's, the substatus code is really helpful to identify why a 404 is returned so you may want to check the IIS Logs for your site to see the substatus and see if the substatus code corresponds to missing mime map (404.3)

If the substatus code for 404 is 3 then you can add the mimemap for excel extension as explained in a similar article on stack overflow Use SVG in Windows Azure Websites

For more details refer to http://blogs.iis.net/tomkmvp/troubleshooting-a-404




回答2:


You need to define a MimeType for .xslx files to let the webserver serve them over http.

in your web.config add these lines

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".xlxs" />
      <mimeMap fileExtension=".xlxs" mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
    </staticContent> 
  </system.webServer>
</configuration>

source for MimeType value: https://stackoverflow.com/a/4212908/3234163



来源:https://stackoverflow.com/questions/31149929/browse-to-file-upload-fails-on-azure-website-small-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!