问题描述
我想确保我的ASP.Net库将在中等信任的工作。我有问题,但是,在我需要禁用位code,如果它正处于中级信任运行。
I am trying to make sure my ASP.Net library will work under Medium Trust. I'm having problems however in that I need to disable a bit of code if it is being run under medium trust.
我如何从C#确定?
具体来说,我试图读取web.config中的customErrors部分,我得到安全错误
Specifically, I'm trying to read the customErrors section from web.config and I'm getting security errors
推荐答案
下面本文介绍一种机制来确定的信任级别:
This article here describes a mechanism to determine the trust level:
找出在ASP.NET 当前信任级别
下面是code以防万一死链接:
Here is the code just in case the link dies:
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;
}
我只是测试它在ASP.NET应用程序MVC3在中,然后完全信任运行,它做什么,它在锡说。
I just tested it in an ASP.NET MVC3 application running at Medium and then Full trust and it does what it says on the tin.
这篇关于如何确定是否当前的应用是中等信任的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!