浏览到文件上传在Azure网站(小文件)失败 [英] Browse to file upload fails on Azure website (small file)

查看:246
本文介绍了浏览到文件上传在Azure网站(小文件)失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以发布天青后上传我的网站上本地运行的.xlsx文件,但404的。 ASP.Net/webforms; C#;

你正在寻找已被删除的资源,更名或暂时不可用。

任何想法,将AP preciated。

 如果(!this.FileUpload1.FileName.Equals(ActionFile.xlsx))
{
    this.tbxAdminStatus.Text =缺少输入文件ActionFile.xlsx;
    返回;
}
其他
{
    // 上传文件
    fileLoc =使用Server.Mappath(〜/上传/+ his.FileUpload1.PostedFile.FileName);    尝试
    {
         this.FileUpload1.PostedFile.SaveAs(fileLoc);
         this.tbxAdminStatus.Text =文件上传ActionFile.xlsx;
    }
    赶上(异常前)
    {
        的Response.Write(错误:+ ex.Message);
    }
}


解决方案

您需要定义的MimeType为 .xslx 文件让Web服务器为他们服务通过HTTP。

的web.config 添加这些行

<?XML版本=1.0编码=UTF-8&GT?;
<结构>
  < system.webServer>
    < staticContent>
      <清除fileExtension = /&GTxlxs。
      <xlxsmimeMap fileExtension = mime类型=应用/ vnd.openxmlformats-officedocument.s preadsheetml.sheet/>
    < / staticContent>
  < /system.webServer>
< /结构>

源的MimeType值: http://stackoverflow.com/a/4212908/3234163

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);
    }
}

解决方案

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: http://stackoverflow.com/a/4212908/3234163

这篇关于浏览到文件上传在Azure网站(小文件)失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆