0

我已经使用 asp.net c# 开发了一个 Web 应用程序。有一个 FileUpload Control 必须上传人员照片。但是当我发布该网站时,它无法正常工作!虽然在本地版本上没有看到任何问题。我一直在尝试以下方法:

  1. 检查 web.config 中的 HttpRuntime => executionTime="60", maxRequestLength="4097151"
  2. 在网上搜索并没有任何结果

这是我的代码:

fupImage.SaveAs(Server.MapPath(@"\UploadedImages\" + fupImage.FileName));
fupImage.SaveAs(Server.MapPath(@"\UploadedImages\" + fupImage.FileName));

这可能有什么问题?

4

1 回答 1

1

确保您已设置 form enctype="multipart/form-data" 并且您保存的路径确实存在并且您有权限。你可以通过调试检查它..

这是完整的代码

<form id="Form1" method="post" action="/home/save" enctype="multipart/form-data">
   <input type="file" name="file" />
    <input type="submit" value="OK" />
</form>

 [HttpPost]
    public ActionResult Save(HttpPostedFileBase file)
    {
        // Verify that the user selected a file
        if (file != null && file.ContentLength > 0) 
        {
            // extract only the fielname
            var fileName = Path.GetFileName(file.FileName);
            // store the file inside ~/App_Data/uploads folder
            var path = Path.Combine(Server.MapPath("~/UploadedImages"), fileName);
            file.SaveAs(path);
        }
        // redirect back to the index action to show the form once again
        return RedirectToAction("Index");        
    }
于 2013-02-24T10:55:46.420 回答