我有一个在VS2010中完美运行的C#Web应用程序,但是当部署到IIS7服务器时,返回“图像未找到图标”。FileNotFoundException IIS7
的一段代码在基本上问题抓住在网络共享位置处的图像的缩略图,操纵和然后推回出到网页。
Web服务器与其尝试访问的文件位于同一网络上。所有访问此网页的用户都位于同一个本地Intranet上。
的应用是在一个这样或那样的分类网络资源节省的存储列表。
当我部署应用程序,它提供了两种错误,我在我的应用程序日志中找到。我觉得这是一个文件权限错误,并且这两个错误是链接的,但我不知道在哪里更改权限以使应用程序正常工作。但是,如果我将“T:\ Published \ Generic.jpg”并将其插入到我的IE地址栏中,则可能会出现此问题。它加载图像。
的用于处理图像的一段代码是这样的:
System.Drawing.Image img;
img = System.Drawing.Image.FromFile(MapPath(Request.QueryString["File"].ToString()));
我已经既没有MapPath方法试了一下。
我尝试调试应用程序,但因为它在VS2010中工作,所以它不会抛出异常,所以我不知道它为什么会在IIS服务器上抛出。
整个堆栈跟踪的要求:imagedrawer.aspx的
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:
内容:
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();
@JKM,当您使用IE访问共享时,IE使用您的凭据。如果IE浏览器有效,它只是证明你有权访问该共享。但是,在IIS/ASP.NET上运行的应用程序正在应用程序池标识下运行(如Guvante所述),因此发生的任何错误都表明该标识不能访问该共享(必须使用UNC路径,每http:// support.microsoft.com/kb/257174)。您需要授予访问共享池身份的权限,或将访问池身份更改为可访问共享的帐户。下次请多关注用户上下文。 – 2012-02-14 02:49:04
将解决方案部署到目标机器并设置正确的应用程序池服务后,它不再注册此错误。 – Sorean 2012-02-14 18:32:22