开发者

System.UnauthorizedAccessException loading file from Disk

开发者 https://www.devze.com 2023-02-17 19:12 出处:网络
Really weird problem loading a file from disk: string path = HttpContext.Current.Server.MapPath(\"~/Datasets/blob.xml\");

Really weird problem loading a file from disk:

string path = HttpContext.Current.Server.MapPath("~/Datasets/blob.xml");
FileStream stream = new FileStream(path, FileMode.Open);

Throws exception:

An exception of type 'System.UnauthorizedAccessException'开发者_开发百科 occurred in mscorlib.dll but was not handled in user code

Additional information: Access to the path 'D:\webroot\afob\Dev\v1.0.x\AFOB\Datasets\blob.xml' is denied.

The strange thing is it was working 5 minutes ago. I checked permissions on the disk and both the Debugger and ASPNET have read/write rights as do I.

Ideas?


Did you dispose the stream the last time you opened it:

string path = HttpContext.Current.Server.MapPath("~/Datasets/blob.xml");
using (var stream = new FileStream(path, FileMode.Open))
{
    ...
}

But in this case I suspect it's really a permissions issue. You could procmon from SysInternals to see exactly what process is trying to open the file and under which account this process executes.

0

精彩评论

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