11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9: Using Code Access <strong>Security</strong> with ASP.NET 241Asserts Full TrustPartial-Trust<strong>Web</strong><strong>Application</strong>WrapperAssembly(GAC)OLE DBDataSourceS<strong>and</strong>boxedFull-Trust CodeADO.NET OLE DBData Providerdem<strong>and</strong>s Full TrustFigure 9.3S<strong>and</strong>boxing OLE DB resource accessS<strong>and</strong>boxingIn this approach, you create a wrapper assembly to encapsulate OLE DB data sourceaccess. This assembly is granted full-trust permissions, which are required to use theADO.NET OLE DB managed provider. To build a s<strong>and</strong>boxed wrapper assembly to call OLE DB data sources1. Create an assembly for your data access code. Configure the assembly version,strong name the assembly, <strong>and</strong> mark it with theAllowPartiallyTrustedCallersAttribute, as follows:[assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyKeyFile(@"..\..\oledbwrapper.snk")][assembly:AllowPartiallyTrustedCallersAttribute()]You must annotate any strong named assembly withAllowPartiallyTrustedCallersAttribute if you want to support partial-trustcallers. This suppresses an implicit link dem<strong>and</strong> for full trust made by the .NETFramework whenever code from a strong named assembly is loaded <strong>and</strong> JITcompiled.2. Request full trust. Although not strictly necessary, requesting full trust is a goodpractice because it allows an administrator to view the assembly’s permissionrequirements by using tools like Permview.exe. To request full trust, request theunrestricted permission set as follows:[assembly: PermissionSet(<strong>Security</strong>Action.RequestMinimum, Unrestricted=true)]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!