zoukankan      html  css  js  c++  java
  • 温习ASP调用C#的DLL并实现用户名密码进行域验证反馈结果

    项目示意图:

    设置:使程序集COM可见

     设置:为程序集签名

     C#类代码:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.DirectoryServices;
     6 namespace ClassLibrary1
     7 {
     8     public class Class1
     9     {
    10         public string msg;
    11         public string pat;
    12         public bool IsAuthenticated(string domain, string username, string pwd)
    13         {
    14             string domainAndUsername = domain + @"\" + username;
    15             pat = "LDAP://" + domain;
    16             DirectoryEntry entry = new DirectoryEntry(pat, domainAndUsername, pwd);
    17             try
    18             {
    19                 //Bind to the native AdsObject to force authentication.
    20                 object obj = entry.NativeObject;
    21                 DirectorySearcher search = new DirectorySearcher(entry);
    22                 search.Filter = "(SAMAccountName=" + username + ")";
    23                 search.PropertiesToLoad.Add("cn");
    24                 SearchResult result = search.FindOne();
    25                 if (null == result)
    26                 {
    27                     return false;
    28                 }
    29                 //Update the new path to the user in the directory.
    30                 pat = result.Path;
    31                 msg = (string)result.Properties["cn"][0];
    32             }
    33             catch (Exception ex)
    34             {
    35                 msg = ex.Message;
    36                 return false;
    37             }
    38 
    39             return true;
    40         }
    41     }
    42 }

    注册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
    %>
  • 相关阅读:
    python列表--查找集合中重复元素的个数
    python3-打印一个进度条
    python3-sys模块
    python3-字符串操作
    python3-深浅复制
    python3-os模块
    接口和抽象类有什么区别
    集合知识
    面向对象的特征有哪些方面
    javadoc时候乱码-编码 GBK 的不可映射字符
  • 原文地址:https://www.cnblogs.com/webczw/p/2872545.html
Copyright © 2011-2022 走看看