从 ASP.Net 3.5 迁移到 4.0 - System.Security.Permissions.FileIOPermission 异常
我确信这不会太难;但我正在挣扎。错误是
异常详细信息: 系统.安全.安全异常: 请求类型许可 '系统.安全.权限.FileIOPermission, mscorlib,版本=4.0.0.0, 文化=中立, 公钥令牌=b77a5c561934e089' 失败。
我正在尝试写入服务器上的文本文件。之前,我必须修改 web.config
文件将信任级别设置为完全。然后一切似乎都奏效了。
我已经更新了我的网站以使用 ASP.NET 4.0;现在我无法做到这一点。我真的没有做太多事情,只是读/写文件。但现在我无法克服这个错误。据我所知,听起来“完整”是 4.0 中的默认设置?
我有一个(实际上)空的 web.config。我尝试添加信任级别以明确将其设置为完整,但似乎没有帮助。
编辑
我目前正在使用 File.AppendAllText
写入文件,并使用 File.ReadAllText
读取内容。
这是IIS7。
如果听起来这与编程无关,我可以通过我的主机的客户支持来解决它。但是,就像我说的,如果我将网站切换回 3.5,效果会很好。当我将其设置为 4.0 时 - 我收到此错误。
I'm sure this can't be too hard; but I'm struggling. The error is
Exception Details:
System.Security.SecurityException:
Request for the permission of type
'System.Security.Permissions.FileIOPermission,
mscorlib, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089'
failed.
I'm trying to write to a text file on the server. Before, I had to modify the web.config
file set the trust level to full. Then it all seemed to work.
I've since updated my site to use ASP.NET 4.0; and now I can't pull it off. I'm really not doing much at all, just reading/writing a file. But now I can't get past the error. From what I've read, it sounds like 'Full' is the default setting in 4.0?
I have a (virtually) empty web.config. I tried adding the trust level to explicitly set it to full but it didn't seem to help.
EDIT
I'm currently using File.AppendAllText
to write to the file and File.ReadAllText
to read the contents.
And this is IIS7.
If it sounds like this isn't programming related, I can take it up with customer support for my host. But, like I said, if I switch my site back to 3.5 it works great. When I set it to 4.0 - I get this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是有关 ASP.NET 4.0 中许多重大变化的白皮书
http://www.asp.net/learn/whitepapers/aspnet4/writing-changes
看起来安全模型进行了重大修改...但看起来我的问题的简短答案是添加:
legacyCasModel 应该为您提供 ASP.NET 早期版本的旧行为。这对我有用。
Here is a whitepaper on many of the breaking changes in ASP.NET 4.0
http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes
It looks like the security model had a significant overhaul...but it looks like the short answer for my problem is to add:
legacyCasModel should give you the old behavior from previous editions of ASP.NET. This worked for me.