2009-07-21 139 views
0

我無法使用FileUpload.SaveAs()或File.WriteAllText()將文件保存在Web服務器上。我保存在該文件夾是文件模式666.無法在網絡服務器上保存文件:System.UnauthorizedAccessException

我的代碼是這樣的:

File.WriteAllText( 「」 在MapPath()+ 「\\ \\廣告test.jpg放在」, 「測試」);

此代碼在Dev中完美工作。服務器。

最好的問候, 拉塞Espeholt

System.UnauthorizedAccessException:對路徑*」被拒絕。 (System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions options,System.IO)中的錯誤代碼爲 。Error.WinIOError(Int32 errorCode,String maybeFullPath) at System.IO.FileStream.Init SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options,String msgPath,Boolean bFromProxy) at System.IO。 FileStream..ctor(String path,FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at System.Web.UI.WebControls.FileUpload.SaveAs(String filename) at *(Object sender,ListViewInsertEventArgs e )

+0

訪問路徑*'被拒絕 - 這是一個實際的錯誤還是您從異常中刪除了路徑? – 2009-07-21 08:17:20

回答

3

您需要爲所需文件夾的機器的ASPNET帳戶授予讀寫權限。 您可以通過打開文件夾屬性 - >安全選項卡來完成。

+0

我已經使用您的評論並將其顯示到webadmin。現在它的作品謝謝:) – 2009-07-22 10:39:06

0

您的錯誤消息指出:

System.UnauthorizedAccessException: Access to the path *' is denied. 

這看起來有點奇怪。你編輯過路徑嗎?或者它是如何顯示的?如果後者出現問題,請致電MapPath

我知道以下內容可能看起來很明顯,但過去我曾多次被假設咬過。

您是否驗證過您認爲您要寫入的文件夾是MapPath(".") + "\\Ads\\test.jpg"實際解決的文件夾?

您是否對「廣告」子文件夾有完整權限?

+0

爲了安全起見,我隱藏了路徑:) – 2009-07-22 10:39:48

相關問題