ASP calls the C # compiled DLL Method
I have been busy with a project for a while, and I want to use ASP to call C # DLL. I have a lot of online qualifications. I have summarized it and wrote an example.
Come out
First, create a class library project
Compile an interface. The ASP object to be called to implement this interface. The Code is as follows (there must be a constructor without parameters)
Using System;
Using System. Runtime. InteropServices;
Namespace Test
{
[Guid ("123AC4E1-BEB0-45a1-BE3F-91BDD16A117A")]
Public interface ITest
{
[DispId (0)]
String TestString ();
}
Public class Test: ITest
{
// Obtain the GUID created from the tool
Public Test ()
{
}
# Region ITest Member
Public string TestString ()
{
Return "Test ";
}
# Endregion
}
Then, execute a strong signature for this class (if this DLL calls other DLL, also need a strong signature), run Visual
Studio 2003. net command prompt, execute sn-k and add the directory of the output DLL, such as sn-k file path \ test. snk, then generate
Open the AssemblyInfo. cs file, and fill in the generated SNK file in [assembly: AssemblyKeyFile ("")].
For example, [assembly: AssemblyKeyFile ("file path \ test. snk")], and then re-compile
Use the regasm tool to register the Assembly, run the Visual Studio 2003. net command prompt, and execute regasm/tlb
DLL file
Then, use the gacutil tool to install the DLL assembly to the Global Assembly Cache, and first run Visual Studio 2003. net.
Command prompt, and then execute the path of the DLL to be registered by gacutil/I
Then you can call the test in asp.
Sn.exe
Regasm.exe
Gacutil.exe
All three tools can be found in the SDK \ v1.1 \ Bin directory under the installation directory of Visual Studio. net 2003.