HighTechTalks DotNet Forums  

SecurityException: Request failed in LoadControl

Dotnet Security microsoft.public.dotnet.security


Discuss SecurityException: Request failed in LoadControl in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Achim Domma
 
Posts: n/a

Default SecurityException: Request failed in LoadControl - 12-14-2006 , 05:52 AM






Hi,

I have a web part which dynamicaly loads an ascx control. If I
configure my sharepoint for full trust, everything works fine. Using
other security settings, I get the following exception:

[SecurityException: Request failed.]
System.Reflection.MethodBase.PerformSecurityCheck( Object obj,
RuntimeMethodHandle method, IntPtr parent, UInt32 invocationFlags) +0
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +189
System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes) +1036
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes) +114
System.Web.HttpRuntime.CreateNonPublicInstance(Typ e type, Object[]
args) +40
System.Web.Configuration.PagesSection.CreateContro lTypeFilter()
+3368024
System.Web.UI.TemplateParser.ProcessConfigSettings () +179
System.Web.UI.TemplateControlParser.ProcessConfigS ettings() +15
System.Web.UI.UserControlParser.ProcessConfigSetti ngs() +9
System.Web.UI.TemplateParser.PrepareParse() +415
System.Web.UI.TemplateParser.Parse() +155

System.Web.Compilation.BaseTemplateBuildProvider.g et_CodeCompilerType()
+105

System.Web.Compilation.BuildProvider.GetCompilerTy peFromBuildProvider(BuildProvider
buildProvider) +54

System.Web.Compilation.BuildProvidersCompiler.Proc essBuildProviders()
+256
System.Web.Compilation.BuildProvidersCompiler.Perf ormBuild() +29
System.Web.Compilation.BuildManager.CompileWebFile (VirtualPath
virtualPath) +279

System.Web.Compilation.BuildManager.GetVPathBuildR esultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile) +580

System.Web.Compilation.BuildManager.GetVPathBuildR esultWithNoAssert(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean
allowCrossApp, Boolean allowBuildInPrecompile) +93
System.Web.UI.TemplateControl.LoadControl(VirtualP ath virtualPath)
+76
System.Web.UI.TemplateControl.LoadControl(String virtualPath) +23

Using Reflector for .Net, I can look into CreateInstanceImpl and see a
check like this:

if (entry1.m_ctor != null)
{
if (!skipVisibilityChecks && entry1.m_bNeedSecurityCheck)
{
MethodBase.PerformSecurityCheck(obj1, entry1.m_hCtorMethodHandle,
this.TypeHandle.Value, 0x10000000);
}
}

Any hint why this check could fail or how to figure out what's the
reason is? I'm working on a custom trust file but have no idea what
permission my code might be missing.

regards,
Achim


Reply With Quote
  #2  
Old   
Achim Domma
 
Posts: n/a

Default Re: SecurityException: Request failed in LoadControl - 12-14-2006 , 09:58 AM






Hi,

I additionally granted System.Security.Permissions.ReflectionPermission
to my code and now the exception is thrown a bit later. Now the call to
System.RuntimeTypeHandle.CreateInstance throws a SecurityException.

Any hint?

Achim


Reply With Quote
  #3  
Old   
Andy
 
Posts: n/a

Default Re: SecurityException: Request failed in LoadControl - 12-15-2006 , 01:19 PM




What version of .NET are you using? The permissions available on the
full/high/medium/low default security policies are different between
frameworks and will determine what parameters you have to override.


Reply With Quote
  #4  
Old   
JD
 
Posts: n/a

Default Re: SecurityException: Request failed in LoadControl - 02-21-2007 , 03:39 PM



Has anyone determined the answer to this issue yet? I am running into the same problem trying to do the same thing.
---
Posted via DotNetSlackers.com

Reply With Quote
  #5  
Old   
jumbox_us@yahoo.com
 
Posts: n/a

Default Re: SecurityException: Request failed in LoadControl - 04-05-2007 , 12:34 PM



I guess this is a late response, however I ran into exact same problem
and thought to share my solution. I couldn't find an answer anywhere.
A configuration recommended by official papers does not appear to work
with User Controls. After some disassembly and debugging, I was able
to solve it with following minimal permission set. Apparently a
template parser wants an entire PermissionSet unrestricted. It is also
worth noting that it uses LinkDemand, which probably explains why if
you deploy a user control with full trust and later switch to custom
set, you may remove all permissions and it will still work.

<SecurityClasses>
...
<SecurityClass Name="SharePointPermission"
Description="Microsoft.SharePoint.Security.SharePo intPermission,
Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" />
<SecurityClass Name="FileIOPermission"
Description="System.Security.Permissions.FileIOPer mission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</SecurityClasses>

<NamedPermissionSets>
...
<PermissionSet class="NamedPermissionSet" version="1"
Name="wss_KS_minimaltrust" Unrestricted="true">
<IPermission class="AspNetHostingPermission" version="1"
Level="Minimal"/>
<IPermission class="SharePointPermission" version="1"
ObjectModel="True"/>
<IPermission class="SecurityPermission" version="1"
Flags="Execution, ControlThread"/>
<IPermission class="WebPartPermission" version="1"
Connections="True"/>
<IPermission class="FileIOPermission" AllFiles="None"
AllLocalFiles="PathDiscovery, Read"/>
</PermissionSet>
...
</NamedPermissionSets>


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.