Asp .Net 4.0 中的部分/完全信任模式验证

发布于 2024-11-28 18:55:01 字数 807 浏览 3 评论 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 技术交流群。

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

发布评论

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

评论(1

人│生佛魔见 2024-12-05 18:55:01

如何在需要完全信任并捕获 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.

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