gpt4 book ai didi

.net - 测试 .NET 应用程序是否在完全信任的情况下运行

转载 作者:行者123 更新时间:2023-12-04 05:53:36 26 4
gpt4 key购买 nike

您如何从 .NET 测试应用程序是否在完全信任的情况下运行?

我的应用程序在 .NET 2.0 中运行,需要使用该框架。

最佳答案

貌似有博客Finding out the current trust level in asp.net这看起来很有希望。我把代码贴在这里以防博客死了。

// Here is a sample code that returns the current trust level, assuming this
// code (or the calling code up the stack), is not loaded from GAC:

AspNetHostingPermissionLevel GetCurrentTrustLevel() {
foreach (AspNetHostingPermissionLevel trustLevel in
new AspNetHostingPermissionLevel [] {
AspNetHostingPermissionLevel.Unrestricted,
AspNetHostingPermissionLevel.High,
AspNetHostingPermissionLevel.Medium,
AspNetHostingPermissionLevel.Low,
AspNetHostingPermissionLevel.Minimal
}) {
try {
new AspNetHostingPermission(trustLevel).Demand();
}
catch (System.Security.SecurityException ) {
continue;
}

return trustLevel;
}
return AspNetHostingPermissionLevel.None;
}

// The result can be cached in a static field
// for the duration of the app domain lifetime.

关于.net - 测试 .NET 应用程序是否在完全信任的情况下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9780537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com