【问题标题】:GDI+ generic error on production server生产服务器上的 GDI+ 通用错误
【发布时间】:2017-08-03 15:04:10
【问题描述】:

我正在努力解决一个得到大量解答的问题,但没有一个给定的解决方案对我有用。 我有一个 ASP.NET WebForms 应用程序,我想在其中存储图片并能够检索它、更改旋转、删除等... 问题是在我的开发环境中一切正常(使用 Visual Studio,甚至在我的本地机器上使用 IIS 8.5)但是当我尝试在我的生产服务器(IIS 10.0)上部署它时,我什至无法上传图片,我只能读图片。 如果我尝试保存、旋转或删除图像,我会收到 GDI+ 一般错误。 这让我觉得这是一个配置或权限问题,因为该应用程序与我的机器上的相同,并且运行良好。

我尝试过的:

  • 返回“.NET v4.5”,我已同意
    对目录具有完全权限的用户,即使是给定的完全访问权限 对“每个人”用户都没有解决问题。
  • 我曾尝试在保存图片后对其进行处理,但我不认为 这是因为当我上传时我没有覆盖任何 文件。
  • "GC.Collect()" 什么也没做,我真的不明白为什么 会有所作为。
  • 我查看了 IIS 的 MIME 类型,发现有“image/jpeg”。

令我不安的是,我在同一个应用程序中有一个文件上传目录(不是图片),它可以工作,所以我猜权限是好的,我对两个目录都有相同的权限。

这是我的图片上传代码:

public static Int64 InsertPhoto(Photo maPhoto)
    {
        ////////////////////////////////////////////////
        // ETAPE 1 : Récupération du numéro de photo
        ////////////////////////////////////////////////
        try
        {
            int? numero = PecV2.DAL.Photo.GetNumeroPhotoMaxByIDIntervention(maPhoto.IDIntervention);
        if (numero.HasValue)
        {
            maPhoto.Numero = numero.Value + 1;
        }
        else
        {
            maPhoto.Numero = 0;
        }

        ////////////////////////////////////////////////
        // ETAPE 2 : Génération des miniatures
        ////////////////////////////////////////////////
        Intervention monIntervention = Intervention.GetIntervention(maPhoto.IDIntervention);
        maPhoto.IDImmeuble = monIntervention.IDImmeuble;
        maPhoto.FileName = maPhoto.IDImmeuble.ToString() + "_" + maPhoto.IDIntervention.ToString() + "_" + maPhoto.Numero.ToString() + ".jpg";

        maPhoto.EnregistrerMiniature(maPhoto.PhotoFull, global::PecV2.BL.Properties.Settings.Default.LargeurPhotoMedium, global::PecV2.BL.Properties.Settings.Default.RepertoirePhotosMedium, maPhoto.FileName);
        maPhoto.EnregistrerMiniature(maPhoto.PhotoFull, global::PecV2.BL.Properties.Settings.Default.LargeurPhotoSmall, global::PecV2.BL.Properties.Settings.Default.RepertoirePhotosSmall, maPhoto.FileName);
        // Encoder...                
        EncoderParameters encParams = new EncoderParameters(1);
        encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100);


        // Codec...
        ImageCodecInfo codecJpeg = null;
        foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders())
            if (codec.MimeType == "image/jpeg")
                codecJpeg = codec;
            //GC.Collect();
            maPhoto.PhotoFull.Save(Path.Combine(global::PecV2.BL.Properties.Settings.Default.RepertoirePhotosFull, maPhoto.FileName), codecJpeg, encParams);
        }
        catch (Exception ex)
        {

            throw ex;
        }
        ////////////////////////////////////////////////
        // ETAPE 3 : Enregistrement en base
        ////////////////////////////////////////////////
        return PecV2.DAL.Photo.InsertPhoto(maPhoto.IDImmeuble,
                                            maPhoto.IDIntervention,
                                            maPhoto.Remarques,
                                            maPhoto.Date,
                                            maPhoto.Numero,
                                            maPhoto.FileName);
    }

 private void EnregistrerMiniature(Bitmap PhotoSource, int DimMax, string RepertoireDestination, string NomFichier)
    {
        double RatioMedium;

        // détermination de l'orientation de la photo originale
        if (PhotoSource.Width >= PhotoSource.Height)
        {
            // photo horizontale
            RatioMedium = PhotoSource.Width / DimMax;
            //
        }
        else
        {
            // photo verticale
            RatioMedium = PhotoSource.Height / DimMax;
        }

        if (RatioMedium < 1)
            RatioMedium = 1;

        // Generation de la photo medium
        Int32 dW;
        Int32 dH;

        // Calcul de la résolution de la vignette par rapport à la largeur
        dW = (Int32)Math.Round(PhotoSource.Width / RatioMedium);
        dH = (Int32)Math.Round(PhotoSource.Height / RatioMedium);


        Bitmap bVignetteMedium = new Bitmap(dW, dH, PixelFormat.Format32bppRgb);

        using (Graphics g = Graphics.FromImage((Image)bVignetteMedium))
        {
            // Temp pour supprimer bordure (G+H) noire
            SolidBrush br = new SolidBrush(Color.White);
            g.FillRectangle(br, 0, 0, dW, dH);

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
            g.DrawImage(PhotoSource, 0, 0, dW, dH);
        }
        // Encoder...                
        EncoderParameters encParams = new EncoderParameters(1);
        encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100);

        // Codec...
        ImageCodecInfo codecJpeg = null;
        foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders())
            if (codec.MimeType == "image/jpeg")
                codecJpeg = codec;
        //Enregistrement de la vignette
        try
        {
            bVignetteMedium.Save(Path.Combine(RepertoireDestination, NomFichier), codecJpeg, encParams);
            bVignetteMedium.Dispose();
        }
        catch (Exception)
        {
            throw;
        }
    }

这是完整的错误堆栈(btnEnregistrer_Click 调用 InsertPhoto):

[ExternalException (0x80004005): Une erreur générique s'est produite dans GDI+.]
 PecV2.WebApp.Intervention.Onglets.o07_Photos.btnEnregistrer_Click(Object sender, EventArgs e) +509
 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11802193
 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1735

----------------------------------- -更新----------------------------------------------------------

我发现问题出在哪里,这是一个 web.config 问题,我试图打开“照片”目录而不是“照片”目录...请不要笑我!!我想知道我怎么错过了那个 X'D

非常感谢你,尼古拉斯。

【问题讨论】:

  • 请问究竟是哪一行引发了错误?我猜我会说这是正确的,但现在还为时过早。
  • System.Drawing Namespace: "System.Drawing 命名空间中的类不支持在 Windows 或 ASP.NET 服务中使用。尝试从这些应用程序类型之一中使用这些类可能会产生意外问题……”。自 .NET 1.1 天以来,该警告(或类似警告)一直存在。

标签: c# asp.net iis gdi+ system.drawing


【解决方案1】:

我发现问题出在哪里,这是一个 web.config 问题,我试图打开“照片”目录而不是“照片”目录...请不要笑我!!我想知道我怎么错过了那个X'D

【讨论】:

    猜你喜欢
    • 2013-08-14
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多