asp.net类生成dll,供asp调用

1.建立类库:dpdll



2.项目>>dpdll属性,设置如下(程序集名字和空间名称,我用的是:DBJK):




注意:选择强名称密钥文件,可以随便起一个名字,但是”使用密码保护密钥文件“去掉。

3. 编写类文件,在类名称上面设置com可见属性[ComVisible(true)],需要引入:using System.Runtime.InteropServices;

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace DBJK
{
    [ComVisible(true)]
    public class Class1
    {
        public string text()
        {
            return "ok";
        }
    }
}


4. 生成DLL。



5. 注册DLL。

步骤:开始菜单==>Vistual Studio==>Vistual Studio Tools==>Vistual Studio 命令提示,

输入regasm d:\dpdll.dll /tlb: dpdll.tlb /codebase,将类型库导入到注册表。提示成功注册。


6.asp调用方法

<%
Set obj = CreateObject("DBJK.Class1")
Response.write(obj.text())
%>

输出结果:


关联文章:

32位DLL注册到64位系统下,需要把IIS中的“启用32位应用程序改为:true










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值