Windows Azure - approot 路径中的访问被拒绝

发布于 2024-12-27 19:12:05 字数 743 浏览 3 评论 0原文

我正在尝试使用 FileStream 打开一个文件(作为内容和始终复制选项包含在我的项目中)。我收到以下错误:

***Access to the path 'E:\approot\PdataParsingRules.xml is denied.***

我正在使用以下代码来获取文件的路径:

Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + @"\", @"approot\PdataParsingRules.xml");

我正在使用以下代码来反序列化我的文件:

ParsingRules rules;
XmlSerializer serializer = new XmlSerializer(typeof(ParsingRules));
fileStream = new FileStream(rulePath, FileMode.Open);
rules = (ParsingRules)serializer.Deserialize(fileStream);
return rules;

当我对我的一个辅助角色实例之一执行 RDC 时(完整运行)信任模式),我看到这个特定文件有读取、读取和;该虚拟机中普通用户的执行权限。管理员和系统对文件具有完全控制权。如果我手动向普通用户授予完全权限,我的反序列化工作正常,但由于明显的原因,这并不能解决问题。

对此的任何想法将不胜感激。

I am trying to open a file (included in my project as Content and Copy Always options) using a FileStream. I am getting the following error:

***Access to the path 'E:\approot\PdataParsingRules.xml is denied.***

I am using the below code to get the path of my file:

Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + @"\", @"approot\PdataParsingRules.xml");

And I am using the below code to de serialize my file:

ParsingRules rules;
XmlSerializer serializer = new XmlSerializer(typeof(ParsingRules));
fileStream = new FileStream(rulePath, FileMode.Open);
rules = (ParsingRules)serializer.Deserialize(fileStream);
return rules;

When I do an RDC to one of my worker role instances (running in full trust mode), I see that this particular file has Read, Read & Execute rights for regular users in that VM. Admin and System have full control on the file. My de serialization works fine if I manually give full rights to regular users but that doesn't solve the problem for obvious reasons.

Any ideas on this would be greatly appreciated.

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

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

发布评论

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

评论(1

空城之時有危險 2025-01-03 19:12:05

查看您正在使用的构造函数的文档,我看到以下内容:

对于没有 FileAccess 参数的构造函数,如果模式参数
设置为追加、写入是默认访问权限。否则,访问
设置为读写。

默认情况下,如果您不使用提升的权限运行您的角色,您的代码就没有对文件的写访问权限。你只能阅读它们。请尝试使用 还指定 FileAccess 模式的构造函数,如下所示:

fileStream = new FileStream(rulePath, FileMode.Open, FileAccess.Read); 

我认为这是你问题的关键。

** 编辑 **

现在我使用两个构造函数进行了测试,我可以确认这(我所描述的)是您的问题。如果您只想读取文件,请使用我引用的构造函数(包括 FileAccess 参数)。如果您还想写入文件,则必须包含启动任务来更改文件权限。

如果您支持后者,

Looking at the documentation for the constructor you are using I see the following:

For constructors without a FileAccess parameter, if the mode parameter
is set to Append, Write is the default access. Otherwise, the access
is set to ReadWrite.

And by default, if you do not run your role with elevated permissions your code does not have WRITE access to the files. You can only read them. Please try using constructor that also specifies the FileAccess mode like this:

fileStream = new FileStream(rulePath, FileMode.Open, FileAccess.Read); 

I think this is the key to your issue.

** EDIT **

Now that I tested using both constructors I can confirm that this (what I described) has been your issue. If you want to just read your file, use the constructor I am refering (including FileAccess parameter). If you want to also write to your file, you have to include a startup task to change file permissions.

If you are for the latter, this thread might be in real help!

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