큰 문제는 해결할 수 없지만 주어진 솔루션 중 어느 것도 나를 위해 작동하지 않습니다. 나는 그림을 저장하고 회전을 변경하고 제거하는 등의 작업을 수행 할 수있는 ASP.NET WebForms 응용 프로그램을 보유하고 있습니다. 문제는 모든 것이 내 devlopment 환경에서 잘 작동한다는 것입니다 (Visual Studio 또는 내 로컬 컴퓨터의 IIS 8.5)하지만 프로덕션 서버 (IIS 10.0)에 배포하려고하면 그림을 업로드 할 수 없으며 그림 만 읽을 수 있습니다. 이미지를 저장, 회전 또는 제거하려고하면 GDI + 일반 오류가 발생합니다. 응용 프로그램이 내 컴퓨터와 동일하고 정상적으로 작동하기 때문에 구성 또는 사용 권한 문제라고 생각합니다.GDI + 프로덕션 서버의 일반 오류
내가 시도하는 것 :
-
% = Environment.UserName %가> "닷넷 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;
}
}
전체 eror 스택이다 (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 문제, 대신 '사진'디렉토리를 열려고했습니다. f 'photo'디렉토리 ... 나를 비웃지 마! 나는 X'D를 놓친 게 궁금합니다.
Nicolas 대단히 감사합니다.
실제로 어떤 오류가 발생합니까? 내 생각에이 권한은 분명하지만 확실하지는 않습니다. – Trey
[System.Drawing 네임 스페이스] (https :// /msdn.microsoft.com/en-us/library/system.drawing(v=vs.110).aspx) : "System.Drawing 네임 스페이스 내의 클래스는 Windows 또는 ASP.NET 서비스에서 사용할 수 없습니다. 이러한 응용 프로그램 유형 중 하나에서 이러한 클래스를 사용하려고하면 예기치 않은 문제가 발생할 수 있습니다. ". 해당 경고 (또는 유사한)는 .NET 1.1 일 이후로 항상 존재했습니다. –