【发布时间】:2012-02-13 23:22:18
【问题描述】:
我有一个在 VS2010 中运行良好的 C# Web 应用程序,但是当部署到 IIS7 服务器时,返回“找不到图像图标”。
有问题的代码实际上是在网络共享位置上抓取图像的缩略图,对其进行操作,然后将其推回网页。
Web 服务器与其尝试访问的文件位于同一网络上。所有访问该网页的用户都在同一个本地内网。
该应用程序是以一种或另一种方式分类的网络保存资源的存储列表。
当我部署应用程序时,它给出了我在应用程序日志中发现的上述两个错误。感觉这是文件权限错误,而且这两个错误是有联系的,但是不知道在哪里修改这个权限才能让应用正常工作。
Exception information:
Exception type: FileNotFoundException
Exception message: T:\Published\Generic.jpg
但是,如果我将“T:\Published\Generic.jpg”插入到我的 IE 地址栏中。它会加载图像。
处理图像的代码部分是这样的:
System.Drawing.Image img;
img = System.Drawing.Image.FromFile(MapPath(Request.QueryString["File"].ToString()));
我已经尝试过使用和不使用 MapPath 方法。
我尝试调试应用程序,但是因为它在 VS2010 中运行,所以它没有抛出异常,所以我不知道为什么它会被扔到 IIS 服务器上。
根据要求进行整个堆栈跟踪:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 13/02/2012 4:16:26 PM
Event time (UTC): 13/02/2012 11:16:26 PM
Event ID: 1f01693f71a2443790a8d83ba06a88a4
Event sequence: 12
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/2/ROOT-3-129736485835718008
Trust level: Full
Application Virtual Path: /
Application Path: C:\inetpub\wwwroot\
Machine name: XXXXXX
Process information:
Process ID: 10768
Process name: w3wp.exe
Account name: IIS APPPOOL\ASP.NET v4.0
Exception information:
Exception type: FileNotFoundException
Exception message: T:\Published\Generic.jpg
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at imagedrawer.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Request URL: http://localhost/imagedrawer.aspx?File=T:\Published\Generic.jpg
Request path: /imagedrawer.aspx
User host address: ::1
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\ASP.NET v4.0
Thread information:
Thread ID: 64
Thread account name: IIS APPPOOL\ASP.NET v4.0
Is impersonating: False
Stack trace: at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at imagedrawer.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
imagedrawer.aspx的内容:
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Drawing.Image img;
img = System.Drawing.Image.FromFile(MapPath(Request.QueryString["File"].ToString()));
if (img.Height > 80 || img.Width > 80)
{
System.Drawing.RectangleF RF = new System.Drawing.RectangleF();
RF.X = 0;
RF.Y = 0;
RF.Height = (img.Height < 80) ? img.Height : 80;
RF.Width = (img.Width < 80) ? img.Width : 80;
System.Drawing.Bitmap bmthumb = (System.Drawing.Bitmap)img.Clone();
System.Drawing.Bitmap bmCrop = bmthumb.Clone(RF, bmthumb.PixelFormat);
img = (System.Drawing.Image)bmCrop;
}
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Request.QueryString["File"].ToString());
Response.AddHeader("Content-Length", ms.ToArray().Length.ToString());
Response.ContentType = "image/jpeg";
Response.BinaryWrite(ms.ToArray());
Response.End();
img.Dispose();
【问题讨论】: