Is there an API to get the current ASP.NET Trust Level?
Asked
Active
Viewed 3,689 times
2 Answers
22
From dmitryr's blog:
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;
}

Aidiakapi
- 6,034
- 4
- 33
- 62

Esteban Araya
- 29,284
- 24
- 107
- 141
0
The following code get current ASP.NET Trust Level programmatically using the official configuration API:
using System.Web;
using System.Web.Configuration;
...
var trust = WebConfigurationManager.GetSection("system.web/trust") as TrustSection;
return trust.Level;

Daniel Fisher lennybacon
- 3,865
- 1
- 30
- 38
-
It was so obvious, sorry. – Daniel Fisher lennybacon Sep 16 '15 at 18:46