.aspx頁面form代碼:
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><asp:FileUpload ID="FileUpload1"
runat="server" />
</div>
</form>
Button1的Click事件代碼:
this.FileUpload1.SaveAs(Server.MapPath("."));
出現如下錯誤:
“/linkupload”應用程式中的伺服器錯誤。
對路徑“D:\HL\上傳下載\linkupload”的訪問被拒絕。
說明: 執行當前 Web 請求期間,出現未處理的異常。請檢查堆疊追蹤資訊,以瞭解有關該錯誤以及代碼中導致錯誤的出處的詳細資料。
異常詳細資料: System.UnauthorizedAccessException: 對路徑“D:\HL\上傳下載\linkupload”的訪問被拒絕。
ASP.NET 未被授權訪問所請求的資源。請考慮授予 ASP.NET 請求標識訪問此資源的許可權。ASP.NET 有一個在應用程式沒有類比時使用的基進程標識(通常,在 IIS 5 上為 {MACHINE}\ASPNET,在 IIS 6 上為網路服務)。如果應用程式正在通過 <identity impersonate="true"/> 類比,則標識將為匿名使用者(通常為 IUSR_MACHINENAME)或經過身分識別驗證的請求使用者。
要將 ASP.NET 存取權限授予某個檔案,請在資源管理員中右擊該檔案,選擇“屬性”,然後選擇“安全”選項卡。單擊“添加”添加適當的使用者或組。反白 ASP.NET 帳戶,選中所需存取權限對應的框。
源錯誤:
只有在偵錯模式下進行編譯時間,產生此未處理異常的原始碼才會顯示出來。若要啟用此功能,請執行以下步驟之一,然後請求 URL: 1. 在產生錯誤的檔案的頂部添加一條“Debug=true”指令。例如: <%@ Page Language="C#" Debug="true" %> 或: 2. 將以下的節添加到應用程式的設定檔中: <configuration> <system.web> <compilation debug="true"/> </system.web> </configuration> 請注意,第二個步驟將使給定應用程式中的所有檔案在偵錯模式下進行編譯;第一個步驟僅使該特定檔案在偵錯模式下進行編譯。 重要事項: 以偵錯模式運行應用程式一定會產生記憶體/效能系統開銷。在部署到生產方案之前,應確保應用程式調試已禁用。
|
堆疊追蹤:
[UnauthorizedAccessException: 對路徑“D:\HL\上傳下載\linkupload”的訪問被拒絕。] System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +1971539 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998 System.IO.FileStream..ctor(String path, FileMode mode) +65 System.Web.HttpPostedFile.SaveAs(String filename) +84 System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +24 _Default.Button1_Click(Object sender, EventArgs e) +44 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +98 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921
|
版本資訊: Microsoft .NET Framework 版本:2.0.50727.832; ASP.NET 版本:2.0.50727.832