温习ASP调用C#的DLL并实现用户名密码进行域验证反馈结果

项目示意图:


设置:使程序集COM可见



设置:为程序集签名


C#类代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
namespace ClassLibrary1
{
    public class Class1
    {
        public string msg;
        public string pat;
        public bool IsAuthenticated(string domain, string username, string pwd)
        {
            string domainAndUsername = domain + @"\" + username;
            pat = "LDAP://" + domain;
            DirectoryEntry entry = new DirectoryEntry(pat, domainAndUsername, pwd);
            try
            {
                //Bind to the native AdsObject to force authentication.
                object obj = entry.NativeObject;
                DirectorySearcher search = new DirectorySearcher(entry);
                search.Filter = "(SAMAccountName=" + username + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();
                if (null == result)
                {
                    return false;
                }
                //Update the new path to the user in the directory.
                pat = result.Path;
                msg = (string)result.Properties["cn"][0];
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }

            return true;
        }
    }
}

注册DLL:

RegAsm ClassLibrary1.dll /codebase

注销DLL:

RegAsm ClassLibrary1.dll /u

注册组件默认位置:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe

ASP调用已注册成功的动态链接库

<%
dim obj,isad
set obj = server.CreateObject("ClassLibrary1.Class1")
isad = obj.IsAuthenticated("xxx.xxx.xxx","username","password")
response.Write(isad&","&obj.pat&","&obj.msg)
set obj = nothing
%>






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值