Friday, December 12, 2014

calling .net dll from asp classic

tested on visual studio pro 2013 and windows 8 / 2012

First, create a new vb / c# project com class component.
Then go to project properties,
Application tab > assembly information > Check Make Assembly com visible
Compile tab
Check Register for com interop
(makesure to sign your app, otherwise you cant register with gac)
Signing tab > Sign the assembly > Create a password

Okay, now to solution explorer on the right side,
Right click on solution and add item
Common items > Code > Com Class

Declare your class with method required,
Remember this class will be visible from outside.

When done building your project,
Go to Build > Build [your projectname]

goto start, find for visual studio tools
run VS2013 x64 Native Tools Command Prompt
(please take note that this is x64 environment).
So we need to run regasm and gacutil from x64 tools, not the default 32bits

Then cd \yourprojectpath\yourclass\bin\Debug\
regasm yourfile.dll
(need to sign assembly)

gacutil -i yourfile.dll

Then you may check if your registry is registered by calling
HKLocal Machine > Software > Classes > YourProjectname.YourObject

okay, then restart iis. and test your dll in asp:
dim foo
set foo = Server.CreateObject("YourProjectname.YourObject")

dim pass
pass = "abA2356!"

if foo.ValidatePassword(pass) then
Response.Write "all ok!"
    response.Write "not ok!"
end if

other references: