生产服务器上的 GDI+ 一般错误
GDI+ generic error on production server
我正在努力解决一个大量回答的问题,但 none 给定的解决方案对我有用。
我有一个 ASP.NET WebForms 应用程序,我想在其中存储图片并能够检索它、更改旋转、删除等...
问题是在我的开发环境中一切正常(使用 visual studio 甚至在我的本地计算机上使用 IIS 8.5)但是当我尝试将它部署到我的生产服务器(IIS 10.0)时,我什至无法上传图片,我只能看图片。
如果我尝试保存、旋转或删除图像,我会收到 GDI+ 一般错误。
这让我觉得这是一个配置或权限问题,因为该应用程序与我的机器上的相同并且运行良好。
我尝试过的:
- <%= Environment.UserName %> returns “.NET v4.5”,我已授予此
对目录具有完全权限的用户,即使是完全访问权限
"Everybody" 用户没有解决问题。
- 我试图在保存图片后处理它们,但我不认为
这是由那个引起的,因为当我上传时我没有覆盖任何
文件。
- "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 问题,我试图打开“照片”目录而不是 'photo' 目录...不要笑我求你了!!我想知道我怎么错过了那个 X'D
非常感谢你,尼古拉斯。
我已经找到问题出处了,这是一个 web.config 问题,我试图打开“照片”目录而不是 'photo' 目录...不要笑我求你了!!我想知道我怎么错过了那个 X'D
我正在努力解决一个大量回答的问题,但 none 给定的解决方案对我有用。 我有一个 ASP.NET WebForms 应用程序,我想在其中存储图片并能够检索它、更改旋转、删除等... 问题是在我的开发环境中一切正常(使用 visual studio 甚至在我的本地计算机上使用 IIS 8.5)但是当我尝试将它部署到我的生产服务器(IIS 10.0)时,我什至无法上传图片,我只能看图片。 如果我尝试保存、旋转或删除图像,我会收到 GDI+ 一般错误。 这让我觉得这是一个配置或权限问题,因为该应用程序与我的机器上的相同并且运行良好。
我尝试过的:
- <%= Environment.UserName %> returns “.NET v4.5”,我已授予此
对目录具有完全权限的用户,即使是完全访问权限 "Everybody" 用户没有解决问题。 - 我试图在保存图片后处理它们,但我不认为 这是由那个引起的,因为当我上传时我没有覆盖任何 文件。
- "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 问题,我试图打开“照片”目录而不是 'photo' 目录...不要笑我求你了!!我想知道我怎么错过了那个 X'D
非常感谢你,尼古拉斯。
我已经找到问题出处了,这是一个 web.config 问题,我试图打开“照片”目录而不是 'photo' 目录...不要笑我求你了!!我想知道我怎么错过了那个 X'D