Why? Because this change allows you to update your COM components on the fly, without reseting and sometimes rebooting you web server to get it to unlock the .dll...
All you need to do is open your COM component in VS.NET... It does most of the work for you.. You should end up with a nice simple class and namespace like
namespace MyWebDLL
{
///
///
public class Hello
{
public string Echo(string name){return name;}
}
}
Then you can set up your asp page to invoke your DLL by using
Dim foo
Set foo = Server.CreateObject("MyWebDLL.Hello")
Response.Write foo.Echo("blah")
In order for ASP to be able to create the object you are going to have to register your assembly... You have two options. According to Microsoft, the preferred method it to generate a strong name and put the assembly in the GAC, which assures that no-one else can make a DLL with the same name as yours and impersonate your class... To do this:
1. Generate a key pair with sn -k MyWebDLL.snk
2. Add the assembly attribute to the assembly
3. Rebuild the assembly
4. Install it into the GAC with gacutil /i MyWebDLL.dll
5. Register it on the machine with regasm /tlb MyWebDLL.dll
I personally do not like to use the GAC for my web apps... I just use the regasm utility with the /codebase switch and ignore the warning that my assembly should be strongly named. (regasm MyWebDLL.dll /tlb /codebase)
An alternate option is to use .NET to build a COM DLL (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vawlkWalkthroughCreatingCOMObjectsWithVisualBasicNET.asp)
No comments:
Post a Comment