Asp .Net 4.0 中的部分/完全信任模式验证
我在Msdn的论坛上发现了类似的问题,但没有答案(你可以检查它此处) .Net 4.0 带有过时的方法
IsUnderHighTrust = SecurityManager.IsGranted(
new AspNetHostingPermission( AspNetHostingPermissionLevel.Unrestricted ) );
作为替代,建议使用 AppDomain.CurrentDomain.PermissionSet
var permission = new PermissionSet(PermissionState.None);
permission.AddPermission(
new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted));
IsUnderHighTrust = permission.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
但 PermissionSet 也需要完全信任模式。
那么显而易见的问题 - 如何在 Asp .Net 4.0 下检查应用程序是否处于完全或中等信任模式?
I found the similar question on Msdn's forum but without answer (you can check it here)
.Net 4.0 came with obsolete method
IsUnderHighTrust = SecurityManager.IsGranted(
new AspNetHostingPermission( AspNetHostingPermissionLevel.Unrestricted ) );
As a replacement it is suggested to use AppDomain.CurrentDomain.PermissionSet
var permission = new PermissionSet(PermissionState.None);
permission.AddPermission(
new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted));
IsUnderHighTrust = permission.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
But PermissionSet is also requires Full trust mode.
So the obvious question - how to check under Asp .Net 4.0 if application is under Full or Medium Trust mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何在需要完全信任并捕获 SecurityException 的代码块(如上面的 PermissionSet 检查)周围放置一个 try/catch?它并不那么漂亮,因为这不是 try/catch 通常应该使用的用途,但似乎它仍然可以实现目标。
How about putting a try/catch around a block of code (like the PermissionSet check above) that requires full-trust and catch on a SecurityException? It's not as pretty because this isn't what a try/catch should normally be used for, but seems it would accomplish the goal none the less.