开发者

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#:

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!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜