I've have a solution with one website and several projects.
The projects all have the AllowPartiallyTrustedCallers
attribute and are strongly-named.
The site works in full trust. However, after set the trust to medium, I get the System.Security.SecurityException: Request failed.
error as soon as I browse to the site.
In my projects, I have calls to LogOnUser
, as well as many calls to variousSystem.DirectoryServices.AccountManagement
methods.
Can this site run with medium trust or do I have to have full trust for all the LDAP calls?
As I mentioned, I've set the AllowPartiallyTrustedCallers
attribute on all projects. Not sure what else to do.
Also, I have no idea what/where the error is being generated. The event logs on the server have nothing in regards to this SecurityException. Is there any way to find out what the error location is so maybe I can attempt to rewrite some code?
[running .NET 4.0 on Win2k8R2]
LogOnUser
, like all P/Invoke calls, requiresSecurityPermission
with theUnmanagedCode
permission flag.System.DirectoryServices.AccountManagement
requires unrestrictedDirectoryServicesPermission
. Neither permission is granted to medium-trust ASP.NET applications by default.The
AllowPartiallyTrustedCallers
attribute allows a full-trust assembly to be used by a partial-trust assembly. In your case, the attribute has no effect because all assemblies in the bin folder are loaded into the partial-trust application domain.If your application is required to run under medium trust, and you have the ability to install assemblies into the GAC, then you can create an assembly containing the code that requires extra permissions, mark the assembly with
AllowPartiallyTrustedCallers
, and put it in the GAC. You will also need toAssert
the required permissions to suppress the stack walks that will still occur.For more information, see the Code Access Security in ASP.NET 4 Applications topic in MSDN Library.