Click here to Skip to main content
6,632,253 members and growing! (18,033 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » General     Intermediate License: The Code Project Open License (CPOL)

Call a .NET component from an ASP Page

By Manoj Kumar G (IND)

How to call a .NET component from VB6.0/ASP developed in either Microsoft Visual Basic® .NET or Microsoft Visual C#® .NET
C#, Windows, .NET, Visual Studio, Dev
Posted:29 Nov 2005
Updated:7 Dec 2005
Views:57,744
Bookmarked:25 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
11 votes for this article.
Popularity: 4.06 Rating: 3.90 out of 5
2 votes, 18.2%
1

2

3
2 votes, 18.2%
4
7 votes, 63.6%
5

Introduction

The following steps outline how to call a .NET component from VB6.0/ASP developed in either Microsoft Visual Basic® .NET or Microsoft Visual C#® .NET.

PART - I

  1. Launch your Visual Studio .NET

  2. Open your .NET Class Project

  3. Add a reference to the System.EnterpriseServices namespace

  4. At the top of the code file, add the following statements to specify the namespaces needed:

    using System.EnterpriseServices;
    using System.Runtime.InteropServices;

    Imports System.EnterpriseServices
    Imports System.Runtime.InteropServices
  5. Add the following statements before the namespace declaration to set the assembly options:

    [assembly: ApplicationName("ClassLibrary1")]
    [assembly: ApplicationActivation(ActivationOption.Server)]
    [assembly: ApplicationAccessControl(false,
    AccessChecksLevel=AccessChecksLevelOption.ApplicationComponent)]

    <Assembly: ApplicationName("ClassLibrary1")>
    <Assembly: ApplicationActivation(ActivationOption.Server)>
    <Assembly:ApplicationAccessControl(False, 
        AccessChecksLevel:=AccessChecksLevelOption.ApplicationComponent)>

ClassLibrary1 – Sample Project

These attributes help specify how the .NET assembly will operate with COM+ services. The ApplicationName attribute allows one to specify the name of the COM+ services application that will host the .NET assembly when it is imported into COM+. You can specify any name you would like here. The ApplicationActivation attribute specifies the type of COM+ application being created. This attribute uses an enumeration called ActivationOption which specifies that the application is a server application. This means that when the component is activated, it will be hosted in a process separate from the process that called it. The ApplicationAccessControl attribute specifies whether the component will perform any access level checks.

PART - II

Generate a strong name for the assembly using the .NET Framework Strong Name Utility (sn.exe). This utility generates a public/private key file that will be incorporated into the assembly. To create this key file, go to a command prompt and change directories to the location where the solution is stored.

Type in the command:

>cd C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin
>sn –k “D:\DotNet Testing\ClassLibrary1\ClassLibrary1\obj\Debug\mykey.snk”

This will create the key file.

Add the strong file name to the assembly by adding an attribute in the AssemblyInfo code file that is part of the project. Locate the AssemblyInfo file in Solution Explorer and click it. In the code file, add the following attribute:

[assembly: AssemblyKeyFile(@"mykey.snk)] 

<Assembly: AssemblyKeyFile("mykey.snk")>

This attribute looks for the strong name key file that was previously created in the folder that was created for the solution. If there is an AssemblyKeyFile attribute in the AssemblyInfo file, replace it with this one.

  1. Build the solution. This will create the DLL file.

  2. Create type library file using your DLL file - Register for COM Interop.

    1. Place the DLL file to your virtual directory /bin folder.

    2. Type in the command:

      >cd “C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322”
      >regasm "D:\DotNet Testing\asp\bin\ClassLibrary1.dll" /tlb /codebase

      This will create the TLB file in your bin folder.

    3. Finally, you can call .NET components from VB6 or ASP:

      Dim Obj
      Set Obj = Server.CreateObject("ClassLibrary1.Class1") 
      Obj.PostCreate

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Manoj Kumar G (IND)


Member
It is an inherent passion for Analytical applications that inspired me to study Physics at the graduate level. During these 3 years I was trained in systematic analysis of physical data and application of Mathematics and in due course of time this passion got transformed into an abiding interest towards automation. This motivated me to go for a higher level application oriented program in Software Development. During the last 6+ years I have enriched myself considerably well by working on various projects which really fine tuned my technical skills. I look forward to put into productive use the knowledge gained / insights developed and at the same time continue to learn enhancing my caliber and pursue a career of excellence, rooted in professional ethics, in the field of Software Development.

I have strong background in C#, ASP.NET, ASP, VB6.0 and SQL server 2000.
Occupation: Web Developer
Location: India India

Other popular .NET Framework articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh)FirstPrevNext
GeneralObject Reference not set to an instance of an object Pinmembernarayananbabun21:28 23 Nov '08  
GeneralYOU ROCK!!! Pinmemberwdwcrazyva13:50 27 Jun '08  
QuestionIntellisense PinmemberBrian Silvers6:17 10 Sep '07  
GeneralError while attempting to create an instance PinmemberAmidu)8:33 24 Dec '06  
GeneralThis is just a copy of an msdn library page... Pinmemberjo0ls17:02 3 Oct '06  
QuestionCall a .NET component from an VB6.0 [modified] Pinmemberbrahmareddy811:47 31 May '06  
AnswerRe: Call a .NET component from an VB6.0 PinmemberAlexander Turlov7:32 16 Jan '07  
GeneralI am getting Error Pinmembershyamaji_20002:09 13 Mar '06  
GeneralCOM object not valid or not registered Pinmemberlieperik6:26 20 Feb '06  
AnswerRe: COM object not valid or not registered PinmemberAlexander Turlov7:30 16 Jan '07  
GeneralRe: COM object not valid or not registered PinmemberZarrinPour5:09 5 Jun '07  
QuestionHelp! Pinmemberjsanjosem22:12 6 Dec '05  
AnswerRe: Help! Pinmemberjsanjosem13:00 7 Dec '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 Dec 2005
Editor: Deeksha Shenoy
Copyright 2005 by Manoj Kumar G (IND)
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project