2017-03-13 14 views
0

大量に回答された問題に苦しんでいますが、特定の解決策のどれも私のために働いていません。 私は画像を保存し、回転を変更したり、削除したりすることができるASP.NET WebFormsアプリケーションを持っています。 事は、すべて私の開発環境(ビジュアルスタジオまたはローカルマシン上のIIS 8.5)、プロダクションサーバー(IIS 10.0)に展開しようとすると、画像をアップロードすることもできず、画像を読み取ることしかできません。 イメージを保存、回転、または削除しようとすると、GDI +の一般的なエラーが発生します。 アプリケーションが自分のマシンと同じで、正常に動作するため、設定またはアクセス権の問題であると思います。GDI +プロダクションサーバーの一般的なエラー

  • <% = Environment.UserName%>を返すの」.NET V4.5" 、私も完全なディレクトリの完全な権限を持つこの
    ユーザーが、許可されました:私は試してみました何

    「Everybody」ユーザーに のアクセス権を与えても問題は解決されません。

  • 私は写真を保存した後に処分しようとしましたが、私は ファイルを上書きしていないので、アップロードしたときにそれが原因です。
  • "GC.Collect()"それは何もしません、私はなぜそれが が違いをもたらすのか理解していませんでした。
  • 私はIISのMIMEタイプを調べて、 "image/jpeg"がそこにあります。

私は、同じアプリケーション内にファイルアップロード用のディレクトリ(写真ではない)があり、それがうまく動作するので、両方のディレクトリに対して同じ権限を持っていると思います。ここで

、写真のアップロードのための私のコードです:

[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 

------------:ここ

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; 
     } 
    } 

はフルERORスタックは(btnEnregistrer_ClickがInsertPhotoを呼び出す)です - - - - - - - - - - - - - - - - - - 更新 - - - - - - - ----------------------------------

問題がどこから発生したかを知りました。 web.configの問題、私は '写真'ディレクトリを開く代わりにしようとしていたf 'photo'ディレクトリ...私を笑わないでください!私はX'Dを見逃してしまったのだろうか

ありがとう、ニコラス。

+0

実際にどのラインがエラーを出すのですか?私はこれが権利だと言いたいですが、確かに早いと言いたいのですが。 – Trey

+0

[System.Drawingネームスペース](https:///msdn.microsoft.com/en-us/library/system.drawing(v=vs.110).aspx): "System.Drawing名前空間内のクラスは、WindowsまたはASP.NETサービス内での使用はサポートされていません。これらのクラスをこれらのアプリケーションタイプの1つから使用しようとすると、予期しない問題が発生する可能性があります... "。その警告(または類似)は、.NET 1.1日以降、常に存在していました。 –

答えて

1

私は問題がどこから来たのか分かりました。web.configの問題でした。私は '写真'ディレクトリの代わりに '写真'ディレクトリを開こうとしていました...私を笑わないでください!私はX'Dを逃したのだろうか

関連する問題