无法在网络服务器上保存文件:System.UnauthorizedAccessException

发布于 2024-07-27 14:52:43 字数 885 浏览 13 评论 0原文

我无法使用 FileUpload.SaveAs() 或 File.WriteAllText() 在网络服务器上保存文件。 我保存的文件夹是 CHMOD 666。

我的代码是这样的:

File.WriteAllText(MapPath(".") + "\\Ads\\test.jpg", "test");

这段代码在 Dev 中完美运行。 服务器。

此致, Lasse Espeholt

System.UnauthorizedAccessException:对路径 *' 的访问被拒绝。 在 System.IO.__Error.WinIOError(Int32 errorCode, String MaybeFullPath) 在System.IO.FileStream.Init(字符串路径,FileMode模式,FileAccess访问,Int32权限,布尔useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,字符串msgPath,布尔bFromProxy) 在 System.IO.FileStream..ctor(字符串路径、FileMode 模式、FileAccess 访问、FileShare 共享、Int32 bufferSize、FileOptions 选项、String msgPath、布尔值 bFromProxy) 在 System.IO.FileStream..ctor(字符串路径,FileMode 模式) 在 System.Web.HttpPostedFile.SaveAs(字符串文件名) 在 System.Web.UI.WebControls.FileUpload.SaveAs(字符串文件名) 在*(对象发送者,ListViewInsertEventArgs e)

I can't save a file on my webserver with FileUpload.SaveAs() or with File.WriteAllText(). The folder I save in is CHMOD 666.

My code is this:

File.WriteAllText(MapPath(".") + "\\Ads\\test.jpg", "test");

This code works perfectly in Dev. server.

Best regards,
Lasse Espeholt

System.UnauthorizedAccessException: Access to the path *' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at 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)
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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守护在此方 2024-08-03 14:52:44

您需要向计算机的 ASPNET 帐户授予所需文件夹的读写权限。
您可以通过打开文件夹属性 -> 来完成此操作。 安全选项卡。

You will need to give read write permissions to machine's ASPNET account for desired folder.
You can do it by opening folder properties -> security tab.

西瓜 2024-08-03 14:52:44

您的错误消息指出:

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

这看起来有点奇怪。 您是否编辑了路径,或者它确实是这样显示的? 如果是后者,那么您对 ​​MapPath 的调用就会出现问题。

我知道以下内容可能看起来很明显,但过去我已经多次被假设所困扰。

您是否已验证您认为要写入的文件夹就是 MapPath(".") + "\\Ads\\test.jpg" 实际上解析为?

您是否也拥有“广告”子文件夹的完整权限?

Your error message states:

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

This looks a little odd. Have you edited the path or is that exactly how it's displayed? If the latter then something is going wrong with your call to MapPath.

I know the following may seem obvious, but I've been bitten by assumptions too many times in the past.

Have you verified that the folder you think you're writing to is the one that MapPath(".") + "\\Ads\\test.jpg" actually resolves to?

Do you have full rights to the "Ads" sub folder as well?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文