我正試圖寫入我的網站上的文件。但是,當試圖用這一行打開文件時: fileName = HostingEnvironment.ApplicationPhysicalPath +「lala.htm」;asp.net tryint寫入服務器上的文件
我得到這個異常: (它得到正確的道路,但仍不允許我寫的話)
訪問路徑「d:\ DZHosts \ LocalUser \ asafz83 \ WWW .asafz83.somee.com \ lala.htm'被拒絕。 描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.UnauthorizedAccessException:對路徑'd:\ DZHosts \ LocalUser \ asafz83 \ www.asafz83.somee.com \ lala.htm'的訪問被拒絕。
ASP.NET未被授權訪問請求的資源。考慮將資源的訪問權限授予ASP.NET請求標識。 ASP.NET具有基本的進程標識(通常是IIS 5上的{MACHINE} \ ASPNET或IIS 6上的網絡服務),如果應用程序未模擬,則使用該標識。如果應用程序正在通過模擬,身份將是匿名用戶(通常爲IUSR_MACHINENAME)或經過身份驗證的請求用戶。
要授予對文件的ASP.NET訪問權,請右鍵單擊資源管理器中的文件,選擇「屬性」並選擇安全選項卡。點擊「添加」添加適當的用戶或組。突出顯示ASP.NET帳戶,然後選中所需訪問權限的複選框。
源錯誤:
在當前web請求的執行過程中生成未處理的異常。關於異常的來源和位置的信息可以使用下面的異常堆棧跟蹤來標識。
堆棧跟蹤:
[UnauthorizedAccessException:訪問路徑 'd:\ DZHosts \ LocalUser \ asafz83 \ www.asafz83.somee.com \ lala.htm'。被拒絕] System.IO .__錯誤(Int32 errorCode,String maybeFullPath)+7716639 System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions選項,SECURITY_ATTRIBUTES secAttrs,String msgPath,布爾型bFromProxy)+1162 System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options)+65 System.IO.StreamWriter.CreateFile(String path, +58 System.IO.StreamWriter.ctor(String path,Boolean append,Encoding encoding,Int32 bufferSize)+58 System.IO.StreamWriter..ctor(String path,Boolean append)+33 Class1。在C:\ Documents and Settings \אסףאזולאי\ My Documents \ Visual Studio 2008 \ Projects \ WebSite6 \ Class1 \ httpFilter.cs中的HTTPFilter.Init(HttpApplication上下文):50 System.Web.HttpApplication.InitModulesCommon()+65 System .Web.HttpApplication.InitModules()43 System.Web.HttpApplication.InitInternal(HttpContext的上下文中,HttpApplicationState狀態,MethodInfo的[]處理程序)729 System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext的上下文中)298 的System.Web .HttpApplicationFactory.GetApplicationInstance(HttpContext上下文)+107 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)+289
HELP請... 任何人...
請重新格式化您問題中的代碼(例如'fileName = HostingEnvironment.ApplicationPhysicalPath +「lala.htm」;'它會使它更具可讀性,而@Darin Dimitrov表示,解決方案似乎處於異常/問題?!? – scherand 2010-05-07 09:15:17