我有一個在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