【发布时间】:2012-01-10 14:34:42
【问题描述】:
我会先做一个简短的总结,然后尽可能添加细节。
我有一个 MVC3 应用程序在两台服务器上运行。我会打电话给他们box1 和box2。两台服务器都运行相同的操作系统、IIS 版本、从 subversion 加载的相同应用程序。 box1 绝对完美无瑕。它可以执行上传到 web.config 中指定的路径。但是,当我尝试使用 box2 上传时,目录已创建,因此我的 Path.Combine 语句工作正常。但从未创建实际上传的文件。
我没有收到任何错误消息,根本没有上传。我认为这是由于路径的应用程序设置。我想也许box2(在不同的域中)没有权利。这不是真的有两个原因
- 当我将路径设置为无法访问的内容时,我确实收到拒绝访问错误。
-
我什至尝试直接在它的硬盘上保存到
box2。仍然只创建文件夹。[HttpPost] public ActionResult Upload(HttpPostedFileBase uploadfile, string id) { var dr405 = new DR405Service().GetDR405ById(new DR405DBContext(), DR405Profile.CurrentUser.TangiblePropertyId); var saveLocation = Path.Combine(DR405Service.SavePath + DR405Profile.CurrentUser.TangiblePropertyId); System.IO.Directory.CreateDirectory(saveLocation); if ((int)uploadfile.ContentLength / 1024 <= 15000) { uploadfile.SaveAs(Path.Combine(saveLocation, Path.GetFileName(uploadfile.FileName))); var file = new dr405files { TangiblePropertyId = DR405Profile.CurrentUser.TangiblePropertyId, FileName = uploadfile.FileName, UploadDate = DateTime.Now }; //dr405.dr405files.Add(file); //c.dr405s.Add(dr405); db.Entry(file).State = file.FileId == 0 ? EntityState.Added : EntityState.Modified; //db.Entry(dr405).State = EntityState.Modified; new DR405Service().Save(db); ViewData["UploadStatus"] = String.Format("File name: {0}, {1}Kb Uploaded Successfully.", uploadfile.FileName, (int)uploadfile.ContentLength / 1024); } else { ViewData["UploadStatus"] = String.Format("File exceeds 15MB upload limit. Please reduce size and try again.", uploadfile.FileName); } return View(); }
这是我正在克服的一些障碍
-
box2是生产服务器,所以无法安装远程调试器 -
box2由另一个组托管,我必须告诉他们如何配置它。他们不会或没有能力弄清楚如何解决这个问题。
更新
虽然不是最优雅的代码,但这确实可以正常工作。
更新 #2
我修改了我的操作以重定向到谷歌,因为我实际上还不能在远程服务器上运行调试器。我发现在box1 上发生了重定向。在box2 上,不会发生重定向。这让我非常确定控制器操作甚至不会在box2 上被调用。这怎么可能?
[HttpPost]
public ActionResult Upload(HttpPostedFileBase uploadfile)
{
Response.Redirect("http://www.google.com");
var dr405 = new DR405Service().GetDR405ById(new DR405DBContext(), DR405Profile.CurrentUser.TangiblePropertyId);
var saveLocation = Path.Combine(DR405Service.SavePath + DR405Profile.CurrentUser.TangiblePropertyId);
System.IO.Directory.CreateDirectory(saveLocation);
if ((int)uploadfile.ContentLength / 1024 <= 15000)
更新 #3
无论我使用哪个版本的 Path.Combine,它都不会改变任何东西。请重新阅读问题。 Action 似乎甚至没有被 box2 调用。
【问题讨论】:
-
即使不保存文件也会写入成功信息吗?
-
不,它只是刷新页面。什么都没有写。
-
仅供参考。你的
Path.Combine有缺陷。 -
@DanielA.White 你能详细说明它有什么缺陷吗?
-
我认为 Daniel 是对的——你不应该在其中使用逗号而不是 + 吗?
标签: c# asp.net-mvc-3 iis-6