.net网站引发404错误

时间:2015-07-02 09:24:52

标签: asp.net .net file iis download

我有一个可以上传的网站,可以在本地上传文件到项目中的文件夹。但是当我使用IIS在局域网中托管网站时,我在尝试下载文件时遇到404错误 - 我可以正常上传文件并将它们显示在正确的文件夹中。

错误:

  

HTTP错误404.0 - 未找到您正在寻找的资源   删除,更改名称或暂时不可用。

这是我的控制器。

下载控制器:

[HttpGet]
public virtual ActionResult Download(string file)
{
    string fullPath = Path.Combine(Server.MapPath("~/SupportAttachments/"), file);
    return File(fullPath, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", file);
}

上传控制器:

[HttpPost]
public JsonResult UploadFiles(string id)
{
    try
    {
        foreach (string file in Request.Files)
        {
            var hpf = Request.Files[file] as HttpPostedFileBase;
            if (hpf.ContentLength == 0)
                continue;
            var fileContent = Request.Files[file];
            if (fileContent != null && fileContent.ContentLength > 0)
            {
                // get a stream
                var stream = fileContent.InputStream;
                // and optionally write the file to disk
                var fileName = id + " " + hpf.FileName;
                var path = Path.Combine(Server.MapPath("~/SupportAttachments/"), Path.GetFileName(fileName));

                // Save the file
                hpf.SaveAs(path); 
            }
        }
    }
    catch (Exception)
    {
        Response.StatusCode = (int)HttpStatusCode.BadRequest;
        return this.Json("Upload failed");
    }

    return this.Json("File uploaded successfully");
}

任何人都可以告诉我为什么在通过IIS托管时无法下载文件?

0 个答案:

没有答案
相关问题