我在遠程託管我的網站上有以下錯誤。我第一次部署它,代碼就像我的本地機器上的魅力一樣。這似乎是一個權限問題,我不需要擔心權限問題,因爲我正在上傳到應用程序目錄中的文件夾中。我不需要爲該儀式授予特殊許可?所以我試圖聯繫我的託管服務提供商,他們說沒有任何關係。我通常可以在網絡託管帳戶中設置權限,以便我可以授予應用程序權限,或者如何解決此問題?我需要模仿用戶嗎?我不應該。該文件夾存在於網站上,並且在網站上還有其他歌曲。訪問它們沒有問題。希望有人能指出我發生了什麼事。我剛剛購買了遠程主機,我不明白它們是如何工作的。遠程託管文件上傳錯誤vb.net
非常感謝。在 '/' 應用
我上傳的代碼
If fuSong.HasFile = True Then
Dim conString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim con As New SqlConnection(conString)
Dim location As String = Path.Combine(Server.MapPath("~/Uploads"), fuSong.FileName)
Dim username As String = Page.User.Identity.Name
Dim Insertcommand As New SqlCommand()
Dim prsongname As New SqlParameter("@songname", SqlDbType.NVarChar)
prsongname.DbType = DbType.[String]
prsongname.Value = name
Insertcommand.Parameters.Add(prsongname)
Dim prusername As New SqlParameter("@username", SqlDbType.NVarChar)
prusername.DbType = DbType.[String]
prusername.Value = username
Insertcommand.Parameters.Add(prusername)
Insertcommand.CommandText = "INSERT INTO Songs(Song_Name, UserName) VALUES (@songname, @username)"
Insertcommand.Connection = con
con.Open()
Insertcommand.ExecuteNonQuery()
fuSong.SaveAs(location) ''''''''' I guess error is here
End If
服務器錯誤。
訪問路徑'D:\ Hosting \ 9078263 \ html \ Uploads \ Sleep Away.mp3'被拒絕。
描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.UnauthorizedAccessException:訪問路徑'D:\ Hosting \ 9078263 \ html \ Uploads \ Sleep Away.mp3'被拒絕。
ASP.NET未被授權訪問請求的資源。考慮將資源的訪問權限授予ASP.NET請求標識。 ASP.NET具有基本進程標識(通常位於IIS 5上的{MACHINE} \ ASPNET或IIS 6和IIS 7上的網絡服務以及IIS 7.5上配置的應用程序池標識),如果應用程序未模擬,則使用該標識。如果應用程序正在通過模擬,身份將是匿名用戶(通常爲IUSR_MACHINENAME)或經過身份驗證的請求用戶。
要授予對文件的ASP.NET訪問權,請右鍵單擊資源管理器中的文件,選擇「屬性」並選擇安全選項卡。點擊「添加」添加適當的用戶或組。突出顯示ASP.NET帳戶,然後選中所需訪問權限的複選框。
源錯誤:
在當前web請求的執行過程中生成未處理的異常。關於異常的來源和位置的信息可以使用下面的異常堆棧跟蹤來標識。
堆棧跟蹤:
[UnauthorizedAccessException:對路徑 'd:\主機\ 9078263 \ HTML \上傳\睡眠Away.mp3' 被拒絕。] System.IO .__ Error.WinIOError(的Int32的errorCode ,String maybeFullPath)+9717806 System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions選項,SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy,Boolean useLongPath )+1142 System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options,String msgPath,Boolean bFromProxy)+78 Sys tem.IO.FileStream..ctor(String path,FileMode mode)+71 System.Web.HttpPostedFile.SaveAs(String filename)+99 profile。btnUpload_Click(對象發件人,EventArgs的)1231
[例外:數據錯誤:未添加記錄] profile.btnUpload_Click(對象發件人,EventArgs的)1374 System.Web.UI.WebControls.Button.OnClick (EventArgs e)+118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)+10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint ,布爾includeStagesAfterAsyncPoint)+5563
不要忘記標記爲其他用戶的答案。 :) – ianbailey 2012-03-21 13:41:52