简体   繁体   English

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

[英]Deleting file from static method error: Access to the path … is denied

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#: 我的主持人发誓ASPNet帐户对某些照片所在的文件夹具有完全访问权限。我正在尝试删除照片,这是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) (在完整的代码中,有一个try catch,并且bool返回值)

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,并显示在页面上。

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! 感谢到目前为止的想法!

IUSR? IUSR? That should be the NETWORK SERVICE or the ASPNET account (depending on the version of IIS) 那应该是NETWORK SERVICE或ASPNET帐户(取决于IIS的版本)

edit: also there is no reason to give IUSR full access. 编辑:也没有理由给予IUSR完全访问权限。 It only needs read access. 它只需要读取访问权限。

If you use a fully-qualified path ("C:\\foo") or if the string isn't recognizable as a path, it'll throw an HttpException. 如果您使用标准路径(“ C:\\ foo”)或无法将字符串识别为路径,则会抛出HttpException。

It would be helpful if you described exactly what you're seeing. 如果您准确描述所看到的内容,将很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM