ASP.NET MVC文件上载在本地构建上工作,在部署后不工作

sri*_*sri 6 c# asp.net asp.net-mvc asp.net-mvc-5

在localhost上构建时,上传图像文件的代码工作正常.但是在部署时,它不起作用而且没有任何错误.

我尝试将imagePath更改/Content/Images/Items/~/Content/Images/Items/Content/Images/Items/.仍然没有解决方案

[HttpPost]
public ActionResult AddProduct(ProductDisplay productDisplay,HttpPostedFileBase upload)
{
    bool isSaved = false;
    string fileName = string.Empty;
    string imagePath = string.Empty;
    try
    {
        if(upload!=null && upload.ContentLength>0)
        {
            fileName = System.IO.Path.GetFileName(upload.FileName);
            imagePath = "/Content/Images/Items/" + fileName;
            upload.SaveAs(Server.MapPath(imagePath));
        }
        else
            imagePath = "/Content/Images/Items/" + "NoImage.jpg";
        productDisplay.ImagePath = imagePath;
        ProductMangementBL balProduct = new ProductMangementBL();
        isSaved = balProduct.AddProduct(productDisplay);
    }
    catch (Exception ex)
    {
        isSaved = false;
    }
    return RedirectToAction("ProductList", new RouteValueDictionary(new { controller = "Product", action = "ProductList", Id = productDisplay.CategoryID }));
}
Run Code Online (Sandbox Code Playgroud)

小智 2

可能需要检查您的应用程序池正在运行,以及它是否具有写入文件的权限。