没有成员资格的活动目录mvc

用户3755065

我需要使用MVC 5在我的应用程序中实现表单和Windows身份验证的混合模式身份验证

这意味着我需要在不使用ASP.NET成员资格提供程序的情况下实现Active Directory身份验证。

创新者一

似乎您想将活动目录用户用作ASP.NET Identity用户。准备一个用于UserLogin信息的方法(用于添加到ASPNET Idenity)

    private UserLoginInfo GetWindowsLoginInfo(string userId, string password)
    {
        string result = IsValidADUser(userId, password);
        return result != "" ? new UserLoginInfo("Windows", result) : null;
    }

并创建一种针对活动目录进行验证的方法

private string IsValidADUser(string userName, string password)
    {

        String adServerName = "LDAP://<<your LDAP String>>";
        var sid = "";

    try
    {
        var directoryEntry = new DirectoryEntry();
        if (!string.IsNullOrEmpty(adServerName))
        {
            directoryEntry.Path = adServerName;
            directoryEntry.Username = userName;
                            directoryEntry.Password = password;
            directoryEntry.AuthenticationType = AuthenticationTypes.Secure;
        }
        else
        {
            throw new Exception("Invalid AD");
        }
        if (directoryEntry.NativeObject != null)
        {
            // Verify the user is locked or not
            DirectorySearcher searcher = new DirectorySearcher(directoryEntry);
                            searcher.Filter = "(SAMAccountName=" + userName + ")";
            searcher.CacheResults = false;
            SearchResult result = searcher.FindOne();

            if (result == null || result.Properties["lockoutTime"][0].ToString() != "0")
            {
                throw new Exception("User Account is locked");
            }
            else
            {
                var sidInBytes = (byte[])result.Properties["objectSid"][0];
                sid = new SecurityIdentifier(sidInBytes, 0).ToString();
                //isValidUser = true;
            }
        }
    }
    catch (Exception ex)
    {
        throw new Exception("AD:" + ex.Message);
    }
    return sid;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

没有成员资格的活动目录mvc

来自分类Dev

类型没有成员

来自分类Dev

班上没有成员

来自分类Dev

UIView没有成员animateWithDuration?

来自分类Dev

类型'AnyObject'的值没有成员''

来自分类Dev

Cl没有成员向量

来自分类Dev

pcl :: io没有成员savePolygonFile

来自分类Dev

子类化:QAbstractItemModel没有成员

来自分类Dev

领域= RLMRealm'没有成员'setDefaultRealmPath'

来自分类Dev

UIWindow?没有成员命名范围

来自分类Dev

命名空间提升没有成员

来自分类Dev

类型“ _”没有成员“ id” SwiftUI

来自分类Dev

C ++类没有成员

来自分类Dev

pcl :: io没有成员savePolygonFile

来自分类Dev

Cl没有成员向量

来自分类Dev

位没有成员ongong

来自分类Dev

cv没有成员BackgroundSubtractorMOG

来自分类Dev

班级没有成员“班级”

来自分类Dev

CIFeature没有成员hasLeftEyePosition

来自分类Dev

类型“ ServerTrustPolicy”没有成员“ certificatesInBundle”

来自分类Dev

错误的UIViewController没有成员

来自分类Dev

类型的值没有成员

来自分类Dev

类型“ UIImagePickerControllerSourceType”没有成员“ photoLibrary”

来自分类Dev

“UITableViewCell”类型的值没有成员

来自分类Dev

vector<Class> 没有成员“函数”

来自分类Dev

类型“UIImage”没有成员“radialGradientImage”

来自分类Dev

Swift:“ Any”没有成员名为element的成员

来自分类Dev

anyobject在SWIFT中没有成员名为objectforkey的成员

来自分类Dev

在MATLAB中检查数组中的成员资格而没有for循环