Asp.net mvc 5 MVC5文件上传和显示

Asp.net mvc 5 MVC5文件上传和显示,asp.net-mvc-5,Asp.net Mvc 5,我目前在一个MVC应用程序中遇到了一个问题,该应用程序将图像上传到文件服务器 public ActionResult UploadFile(HttpPostedFileBase file, string newFileName) { try { if (file.ContentLength > 0) { Bitmap bm = new Bitmap(file.Inpu

我目前在一个MVC应用程序中遇到了一个问题,该应用程序将图像上传到文件服务器

 public ActionResult UploadFile(HttpPostedFileBase file, string newFileName)
    {

        try
        {
            if (file.ContentLength > 0)
            {
                Bitmap bm = new Bitmap(file.InputStream);
                Bitmap final = new Bitmap(bm, 150, 150);
                final.SetResolution(72.0F, 72.0F);

                string _FileName = newFileName + ".jpg";
                string _path = Path.Combine(ConfigurationManager.AppSettings["imageDirectory"], _FileName);
                final.Save(_path,System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            ViewBag.Message = "File Uploaded Successfully!!";
            return RedirectToAction("Index");
        }
        catch
        {
            ViewBag.Message = "File upload failed!!";
            return RedirectToAction("Error");
        }
    }
因此,用户选择一个文件并将其上载到Windows共享。这段代码在我使用IISExpress的机器和我们的测试服务器上运行。当部署到我们的生产服务器时,它似乎可以重定向到索引,但文件服务器上的文件从未更改

IISExpress、测试服务器和生产服务器也都指向同一个文件目录


在进行故障排除时遇到的另一个问题是,使用应用程序的FQDN时,文件服务器中的映像不显示。因此无法显示图片,但会显示图像。这只是另一个奇怪的问题,在测试中根本没有出现

这里是问题和解决方案
如果它在您的开发系统上工作,那么问题是您没有授予对app_数据文件夹的读写访问权。HttpPostedFileBase始终将文件临时上载到App_Store中,Save()方法从中获取文件。如果您没有App_数据文件夹,请创建它。您必须为服务器上的IIS\U用户授予完全读写权限