尝试使用活动目录而不是ADFS时,我的网站崩溃了,我该怎么办?

时间:2018-10-03 17:01:53

标签: c# adfs

我有一些仅在使用活动目录时有效的代码,但是发布时却出现错误。

///允许Active Directory凭据从全局退订中删除某人

    protected void Remove_Click(object sender, EventArgs e)
    {


        using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "Domain"))
        {

            // find the group in question
            GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, "IT Group");

            if (group != null)
            { // remove user}

这现在使网页崩溃,并且出现以下错误:

运行时错误 说明:服务器上发生应用程序错误。该应用程序的当前自定义错误设置阻止应用程序错误的详细信息被远程查看(出于安全原因)。但是,可以由运行在本地服务器计算机上的浏览器查看它。

1 个答案:

答案 0 :(得分:0)

更新:

主要用户不能与ASP.NET表单一起使用,而是必须使用声明表单并检查您的声明/角色。

    // Cast the Thread.CurrentPrincipal
        ClaimsPrincipal icp = User as ClaimsPrincipal;

   // Access IClaimsIdentity which contains claims
        ClaimsIdentity claimsIdentity = (ClaimsIdentity)icp.Identity;

  // what we are doing here is using a for each to get to the claim         
        foreach (Claim claim in claimsIdentity.Claims)
        {
 //The claim we are looking for is in this directory /groupsid
            if (claim.Type == "http://schemas.microsoft.com/claims/groupsid")
            {
 //We use a for loop to go through this because it reads it like a JSON and will either pull the first or last
//Basic for loop incrementing until it finds our group (IT ALL)
                for (int i = 0; i <= 0; i++)
                {
//If our claim contains IT ALL (which it does) then do something...
                    if (claim.Value.Contains("Name of Group"))
                    {
//I'm storing the result here so we can call it otherwise we lose it...
lblResultq.Text = (claim.Value.ToString());

希望这对以后会有帮助!