从静态方法删除文件错误:访问路径...被拒绝

发布于 2024-12-07 17:18:43 字数 538 浏览 3 评论 0原文

我的主机发誓 ASPNet 帐户可以完全访问某些照片所在的文件夹。我正在尝试删除一张照片,这是 C#:(

public static bool Delete(string pathAndFilename)
{
    var path = HttpContext.Current.Server.MapPath(pathAndFilename);
    File.Delete(path);
}

在完整代码中,其中有一个 try catch 和 bool 返回值)

更新:现在本地开发盒上也发生这种情况。这是我已经尝试过的。

我将当前用户放入ViewBag中,并将其显示在页面上。

ViewBag.Account = HttpContext.User.Identity.Name;

在开发框中,它显示了我当前登录的用户帐户,该帐户可以完全控制项目中的每个文件和文件夹。

我检查了打开的文件,我尝试删除的照片未打开。

将尝试捕获更详细的异常。感谢到目前为止的想法!

My host swears the ASPNet account has full access to the folder some photos reside in. I'm trying to delete a photo, here's the C#:

public static bool Delete(string pathAndFilename)
{
    var path = HttpContext.Current.Server.MapPath(pathAndFilename);
    File.Delete(path);
}

(in the full code, there's a try catch in there, and bool return values)

Update: this is happening on local development box too now. Here's what I have been able to try.

I put the current user into the ViewBag, and show it on the page.

ViewBag.Account = HttpContext.User.Identity.Name;

On the dev box, it shows my currently logged in user account, which has full control of every file and folder in the project.

I checked open files, the photo I'm trying to delete wasn't open.

Will try to capture more detailed exceptions. Thanks for the ideas so far!

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

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

发布评论

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

评论(2

苦妄 2024-12-14 17:18:43

IUSR?那应该是 NETWORK SERVICE 或 ASPNET 帐户(取决于 IIS 的版本)

编辑:也没有理由授予 IUSR 完全访问权限。它只需要读取权限。

IUSR? That should be the NETWORK SERVICE or the ASPNET account (depending on the version of IIS)

edit: also there is no reason to give IUSR full access. It only needs read access.

被你宠の有点坏 2024-12-14 17:18:43

如果您使用完全限定路径(“C:\foo”)或者字符串无法识别为路径,则会抛出 HttpException。

如果您准确地描述您所看到的内容将会很有帮助。

If you use a fully-qualified path ("C:\foo") or if the string isn't recognizable as a path, it'll throw an HttpException.

It would be helpful if you described exactly what you're seeing.

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