首页 > 解决方案 > 我在实时 Web 服务器中上传图像,服务器响应错误,而图像在 Visual Studio 的本地服务器上成功上传

问题描述

我在 Asp.net mvc 中开发了一个网站,并将数据存储在 sql server 数据库中。我正在上传图片,在项目文件夹目录中,图片已成功上传到数据库中的本地服务器上。

但问题是,当我上传图片时,实时服务器出错,我已经购买了共享服务器,我已经在其中部署了我的网站。

以下代码用于保存图像,它在本地服务器上正常工作,但在实时服务器上出现错误。

    public string SaveImagingData(string fileName, HttpPostedFileBase image)
    {

        // your configuration here...
        string miliSec = DateTime.Now.Ticks.ToString();
        string imageName = null;
        string physicalPath = "~/Content/images/";

        if (image != null && image.ContentLength > 0)
        {
            imageName = Regex.Replace(fileName, @"\s", "_") + "_" + miliSec + Path.GetExtension(Path.GetFileName(image.FileName));
            string path = Server.MapPath(physicalPath + imageName);

            // save image in folder
            image.SaveAs(path);

        }
        return imageName;
    }

标签: c#sql-serverasp.net-mvc

解决方案


推荐阅读