gpt4 book ai didi

c# - 访问路径被拒绝

转载 作者:IT王子 更新时间:2023-10-29 03:31:19 25 4
gpt4 key购买 nike

我正在尝试将图像保存到 .NET C# 中的文件夹,但出现此异常:

Access to the path 'C:\inetpub\wwwroot\mysite\images\savehere' is denied.The error occured at mscorlib because    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, Boolean useLongPath)
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)

我把这个文件夹(savehere)的完全控制权给了network serviceiis_iusrs,甚至把完全控制权给了everyone,但仍然得到这个异常(exception)。我尝试通过资源管理器和 IIS 管理器授予访问权限,但还是不行

我在 Windows Server 2008 R2 和 IIS 7.5 上执行此操作,我需要向谁授予访问权限?

最佳答案

Access to the path 'C:\inetpub\wwwroot\mysite\images\savehere' is denied

仔细阅读消息。您正在尝试保存到与目录同名的文件。那行不通,您不能用一个新文件覆盖一个充满文件的目录。这将导致无法诊断的数据丢失,“访问路径被拒绝”是文件系统反击以防止这种情况发生。

异常消息并不理想,但它直接来自操作系统,而且是一成不变的。该框架通常会添加额外的检查以生成更好的消息,但这是网络上的昂贵测试。性能也是一个特性。

您需要使用像“C:\inetpub\wwwroot\mysite\images\savehere\mumble.jpg”这样的名称。考虑 Path.Combine()可靠地生成路径名。

关于c# - 访问路径被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4877741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com