CSharp DOT NET Access from classic ASP

To access C# .NET classes from a Classic ASP pages through Dynamic Link Library (DLL).

CSharp DOT NET Access from classic ASP

In the age of .NET managed code, it is very much painful to write code in Classic ASP. But you have to face such a situation for giving support in old classic ASP application where you cannot get .NET Framework facilities by default. In this post I want to explain how you get all .NET facilities in classic ASP pages. Here I will use C# as a .NET language.

Step for Get it Done

  1. Lets consider you are working on the directory E:\work\rd
  2. write a C#.NET application in the MyTest.cs file which will do a multiplication
  3. Now add the following namespace into your program file MyTest.cs
    
    using System.EnterpriseServices;
    using System.Runtime.InteropServices;
    
  4. Also add the following name space for strong key
    using System.Reflection; using System.Runtime.Co
     using System.Reflection; using System.Runtime.CompilerServices; 
    Add for following assembly information into the Mytest.cs. here MyClass is used as name u can give any name u want . [I will discuss about “key.snk” after completing the MyTest.cs]
    [assembly: ApplicationName("MyClass")]
    [assembly: ApplicationActivation(ActivationOption.Server)]
    [assembly: ApplicationAccessControl(false,AccessChecksLevel=
    AccessChecksLevelOption.ApplicationComponent)]
    [assembly: AssemblyKeyFile("key.snk")]
     
    
    
  5. Now the write a method into your class with do multiplication operation
    namespace erpbd.Library
    {
        public class TestApp
        {
            public string Multiply(int x, int y)
            {
                return "The result is :" + (x * y); 
            }
        }
    } 
    
    
    
    complete code is given in “RD_CODES.zip”
  6. SNK is a Strong name utility. We have to create a “key.snk”. consider that visual studio 2005 is installed in your pc go to start>all programs>Visual studio 2005>visual stdion command prompt . now go to your working direcrory then write the command sn –k key.snk [follow the snapshot]
  7. Now you have to make dll file with the following command csc /target:library /out:ErpLib.DLL MyTest.cs ( if you got any warning then ingnore it )
  8. Now you have to make a tlb file with the following command regasm "E:\work\rd\ErpLib.DLL" /tlb /codebase Step 7 and 8 is displayed in following snapshot
  9. write a ASP page which will contain the flowing VBScript code
    
    
     
  10. Now browser the ASP page from your browser then you will get the following output.

 

Tags:C# .NET ASP 
Comments(0) Posted By Saiket | 9/18/2009 12:00:00 AM