问题描述
很奇怪的问题,从磁盘装载文件:
Really weird problem loading a file from disk:
string path = HttpContext.Current.Server.MapPath("~/Datasets/blob.xml");
FileStream stream = new FileStream(path, FileMode.Open);
抛出异常:
型System.UnauthorizedAccessException的的异常出现在mscorlib.dll但在用户code没有处理
An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code
其他信息:访问路径D:\\ webroot的\\ afob \\开发\\ v1.0.x \\ AFOB \\数据集\\ blob.xml'。被拒绝
Additional information: Access to the path 'D:\webroot\afob\Dev\v1.0.x\AFOB\Datasets\blob.xml' is denied.
奇怪的是,它正在5分钟前。我检查了磁盘和两个调试器和ASPNET权限具有读/写权限为我做的。
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.
想法?
推荐答案
你处分流,你打开了它的最后一次:
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))
{
...
}
但在这种情况下,我怀疑这是一个真正的权限问题。你可以从Sysinternals的,看看到底是什么程序试图打开该文件,在哪个帐户下这个过程中执行。
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.
这篇关于从磁盘System.UnauthorizedAccessException的加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!