ASP calls C # DLL

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.