2013-02-24 62 views
0

我使用asp.net c#开发了一个Web应用程序。有一个FileUpload控件必须上传人员照片。但是,当我发布网站时,它无法正常工作!虽然在本地版本没有看到问题。我一直在尝试以下操作:在web.config => executionTime = “60”FileUpload在本地运行良好,但不能很好地发布项目

  1. 检查的httpRuntime,另一maxRequestLength = “4097151”
  2. 搜索网络并没有在出来

这里是我的代码:

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

这可能是什么问题?

+0

IIS是否有访问保存在文件夹UploadedImages文件? – 2013-02-24 10:51:00

回答

1

确保已经设置了表单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");   
    } 
+1

问题中没有MVC标签 – devio 2013-02-24 11:54:07

相关问题