Install strong-named assemblies in the global assembly cache
for ASP.NET 1.0 and 1.1 Web applications. The following steps describe how to
install a strong-named assembly in the global assembly cache, and explain how
to use the
AllowPartiallyTrustedCallersAttribute:
Install a Strong-Named Assembly in the Global
Assembly Cache
You can use the global assembly cache to share assemblies across
many applications. To install the strong-named assembly in the global assembly
cache, follow these steps:
- To create a strong-name assembly, follow the steps in the
"More Information" section of this article.
- Open Visual Studio .NET Command Prompt, and then type the
following command: gacutil -I "C:\[PathToBinDirectoryInVSProject]\sampledll.dll
Note:
sampledll.dll is the name of the DLL that is signed with strong
name.
Add the APTCA
Assemblies that are intended to be called by partially trusted
code declare their intent by the assembly-level custom attribute
AllowPartiallyTrustedCallers. To mark the strong-named assembly with APTCA, follow these
steps:
- To create a strong-name assembly, follow the steps in the
"More Information" section of this article.
- Replace the code in Class1 with the following
code:
Visual C# .NET Codeusing System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
[assembly: AssemblyKeyFile("..\\..\\key.snk")]
[assembly:AllowPartiallyTrustedCallers]
namespace SNAssemblyTest
{
public class Class1
{ // Test Class
}
}
Visual Basic .NET CodeImports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Security
<Assembly: AssemblyKeyFile("..\..\key.snk")>
<Assembly: AllowPartiallyTrustedCallers>
Public Class Class1
' Test Class
End Class
Note Only apply the
AllowPartiallyTrustedCallersAttribute after you have considered the security implications and have
taken the necessary precautions. These precautions include a code review
against the secure coding guidelines that are described in the "Cause" section
of this article. Only apply this attribute to assemblies if the following
criteria are met:
- The assemblies have been designed and been built with
explicit attention to security considerations to help protect them against all
callers, including potentially malicious callers.
- Appropriate security testing with partially trusted code is
completed before the code is released.