小编Ser*_*ril的帖子

递归检查活动目录组成员身份

所以我对活动目录中的递归组有疑问.我有一个方法来检查用户ID是否在组中.效果很好.今天发现它不检查递归组成员资格,我不太确定如何(或者如果)有办法做到这一点.这是我到目前为止非递归的内容:

public static bool CheckGroupMembership(string userID, string groupName, string Domain)
{
  bool isMember = false;

  PrincipalContext ADDomain = new PrincipalContext(ContextType.Domain, Domain);
  UserPrincipal user = UserPrincipal.FindByIdentity(ADDomain, userID);

  if (user.IsMemberOf(ADDomain, IdentityType.Name, groupName.Trim()))
  {
    isMember = true;
  }

  return isMember;
}
Run Code Online (Sandbox Code Playgroud)

我已经看到了一些关于目录搜索器的东西,但我对直接使用AD有些新意,虽然我理解了这些概念,但其他一些东西对我来说仍然有点遗失.

谢谢!

active-directory group-membership c#-4.0

10
推荐指数
2
解决办法
1万
查看次数

C#Active Directory PrincipalContext/UserPrincipal.IsMemberOf错误

所以我有一个问题,老实说我不太确定该怎么问.基本上我运行时有一些代码可以在我的本地机器上运行.一旦我将它发布到我们的开发Web服务器,它就会失败.我不确定这是IIS安装问题,web.config问题还是编码问题.

这是代码片段

    bool isMember = false;

    PrincipalContext ADDomain = new PrincipalContext(ContextType.Domain);
    UserPrincipal user = UserPrincipal.FindByIdentity(ADDomain, userID);

    if (user.IsMemberOf(ADDomain, IdentityType.Name, groupName.Trim()))
    {
        isMember = true;
    }

    return isMember;
Run Code Online (Sandbox Code Playgroud)

我传入用户名和组的地方,它告诉我该用户是否是该组中的成员.没问题.在我的机器上工作得很好.我将该代码发布到网络服务器,当它到达该行时它就失败了

UserPrincipal user = UserPrincipal.FindByIdentity(ADDomain, userID); 
Run Code Online (Sandbox Code Playgroud)

它会抛出此错误:

[DirectoryServicesCOMException(0x80072020):发生操作错误.]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)+788
System.DirectoryServices.DirectoryEntry.Bind()+44
System.DirectoryServices.DirectoryEntry.get_AdsObject()+ 42
System.DirectoryServices .PropertyValueCollection.PopulateList()+29
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry,String propertyName)+63
System.DirectoryServices.PropertyCollection.get_Item(String propertyName)+163 System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()+ 521217
System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()51
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()141
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()42
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper( PrincipalContext上下文,类型principalType,Nullable`1 identityType,Str ing IdentityValue,DateTime refDate)+29
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context,String identityValue)+95
Cosmic.Web.Login.btnSubmit_Click(Object sender,EventArgs e)在C:\ cosmic\Cosmic.Web\Login.aspx.cs:79
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+3691

任何可能失败的想法?

c# directoryservices active-directory

7
推荐指数
1
解决办法
2万
查看次数

ASP/C#会话变量 - 未将对象引用设置为对象的实例

我对ASP/C#有点新,我遇到了会话变量的问题(可能很简单).我的项目有一个Site.Master,其中会话变量在Page_Load方法下设置,如下所示:

    protected void Page_Load(object sender, EventArgs e)
    {

        if ((Session)["UserID"]==null || (Session)["UserID"].ToString() == "")
        {
            (Session)["UserID"] = HttpContext.Current.User.Identity.Name.ToString();
            SqlDataReader dr = Sprocs.GetPermissionGroups();

            string groupList = "";

            while (dr.Read())
            {
            if (groupList != "")
                    {
                        groupList = groupList + "|" + dr["WG_Group"].ToString();
                    }
                    else
                    {
                        groupList = dr["WG_Group"].ToString();
                    }
            }
            dr.Close();

            if (groupList != "")
            {
                (Session)["UserGroups"] = groupList;
            }
        }
Run Code Online (Sandbox Code Playgroud)

这确实有效.如果我将会话变量'UserGroups'转储到此方法中的标签或其他内容,它会正确显示变量内容.

所以,当我尝试访问同一个会话变量时,我的问题在于另一个页面(比如default.aspx).在另一页的Page_Load方法中,我尝试这样做:

    protected void Page_Load(object sender, EventArgs e)
    {
            string GroupList = HttpContext.Current.Session["UserGroups"].ToString();
            //some code with the variables here
    } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net session

5
推荐指数
1
解决办法
4万
查看次数

使用 TimeZoneInfo.GetSystemTimeZones() 时获取 Windows 时区索引;

所以我一直在努力解决的问题是在 .net 4 (C#) 中提取时区列表以填充表单上的下拉列表。我知道我可以这样做:

var TimeZoneList = TimeZoneInfo.GetSystemTimeZones();
Run Code Online (Sandbox Code Playgroud)

它将检索 TimeZoneInfo 类中具有“Id”属性的时区列表。不过,该 ID 不是 Microsoft 时区索引。

例如,对于东部时间,“Id”只是“东部标准时间”,而内部索引为“35”。(其余索引位于:http://msdn.microsoft.com/en-us/library/ms912391( v=winembedded.11).aspx )

是否有某种方法可以从 TimeZoneInfo.GetSystemTimeZones() 获取这些索引,或者是否有其他方法可以调用来查找这些索引?我知道我可以创建一个 switch case 或一堆 if 语句来检查每个 ID 并匹配索引值,但我认为必须有更好的方法。

谢谢!

c# asp.net timezone .net-4.0

5
推荐指数
1
解决办法
3202
查看次数

用小于/大于符号(< 和 >)填充文本框

所以我遇到了一些问题,在我正在开发的网站的各个部分,我在不同的地方显示了一些包含 < 和 > 符号的日志。好吧,当我显示日志时,它工作正常。当然,每当我离开时,我都会收到以下错误:

从客户端检测到潜在危险的 Request.Form 值...

现在我明白这是因为 < 和 > 是我得到的 html 特殊字符。但是,有没有办法禁用或以某种方式允许页面显示/处理这些?我知道我可以将这些字符从它们可能出现的任何地方删除,但如果不是必须的话,我宁愿不要。

有什么建议?

c# asp.net postback

4
推荐指数
1
解决办法
6287
查看次数