当前位置: 首页>>代码示例>>C#>>正文


C# SecurityIdentifier.IsAccountSid方法代码示例

本文整理汇总了C#中System.Security.Principal.SecurityIdentifier.IsAccountSid方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier.IsAccountSid方法的具体用法?C# SecurityIdentifier.IsAccountSid怎么用?C# SecurityIdentifier.IsAccountSid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Principal.SecurityIdentifier的用法示例。


在下文中一共展示了SecurityIdentifier.IsAccountSid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AreSidsInSameDomain

		internal static bool AreSidsInSameDomain(SecurityIdentifier sid1, SecurityIdentifier sid2)
		{
			if (!sid1.IsAccountSid() || !sid2.IsAccountSid())
			{
				return false;
			}
			else
			{
				return sid1.AccountDomainSid.Equals(sid2.AccountDomainSid);
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:ADUtils.cs

示例2: GetUpnFromSelection

        private string GetUpnFromSelection(UnsafeNativeMethods.DsSelection selection)
        {
            if (!string.IsNullOrEmpty(selection.pwzUPN))
            {
                return selection.pwzUPN;
            }

            const string sidPropertyName = "objectSid";
            string upn = selection.pwzADsPath;

            // Try to get the UPN value from AD path
            try
            {
                using (DirectoryEntry entry = new DirectoryEntry(upn))
                {
                    if (entry.Properties.Contains(sidPropertyName))
                    {
                        SecurityIdentifier sid = new SecurityIdentifier((byte[])entry.Properties[sidPropertyName].Value, 0);
                        if (sid.IsAccountSid())
                        {
                            NTAccount acc = (NTAccount)sid.Translate(typeof(NTAccount));
                            upn = acc.Value;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
            }

            return upn;
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:33,代码来源:DsObjectPickerDialog.cs

示例3: Main

        static void Main(string[] args)
        {
            // domainSid: WindowsIdentity.GetCurrent().User.AccountDomainSid);
            if (args.Length > 0)
            {
                if (args[0].StartsWith("-?") ||
                    args[0].StartsWith("-h") ||
                    args[0].StartsWith("-help") ||
                    args[0].StartsWith("/?") ||
                    args[0].StartsWith("/h") ||
                    args[0].StartsWith("/help"))
                {
                    ShowHelp();
                }
                else if (Enum.IsDefined(typeof(WellKnownSidType), args[0]))
                {
                    try
                    {
                        WellKnownSidType sidType = (WellKnownSidType)Enum.Parse(typeof(WellKnownSidType), args[0], false);

                        SecurityIdentifier sid = null;
                        if (args[0].StartsWith("Account"))
                        {
                            sid = new SecurityIdentifier(sidType, WindowsIdentity.GetCurrent().User.AccountDomainSid);
                        }
                        else
                        {
                            sid = new SecurityIdentifier(sidType, null);
                        }

                        NTAccount NTUser = (NTAccount)sid.Translate(typeof(System.Security.Principal.NTAccount));
                        Console.WriteLine("[" + sidType.ToString() + "]");
                        Console.WriteLine("Name=" + NTUser.ToString());
                        Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\")+1));
                        Console.WriteLine("SID=" + sid.ToString());
                        Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    if (args[0].StartsWith("S-"))
                    {
                        try
                        {
                            SecurityIdentifier sid = new SecurityIdentifier(args[0]);
                            NTAccount NTUser = (NTAccount)sid.Translate(typeof(System.Security.Principal.NTAccount));

                            Console.WriteLine("[" + sid.ToString() + "]");
                            Console.WriteLine("Name=" + NTUser.ToString());
                            Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\") + 1));
                            Console.WriteLine("SID=" + sid.ToString());
                            Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            NTAccount NTUser = new NTAccount(args[0]);
                            SecurityIdentifier sid = (SecurityIdentifier)NTUser.Translate(typeof(SecurityIdentifier));

                            Console.WriteLine("[" + NTUser.ToString() + "]");
                            Console.WriteLine("Name=" + NTUser.ToString());
                            Console.WriteLine("Shortname=" + NTUser.ToString().Substring(NTUser.ToString().IndexOf("\\") + 1));
                            Console.WriteLine("SID=" + sid.ToString());
                            Console.WriteLine("IsAccountSid=" + sid.IsAccountSid().ToString().ToUpper());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
            else
            {
                ShowHelp();
            }
        }
开发者ID:andif888,项目名称:SidToUser,代码行数:88,代码来源:Program.cs


注:本文中的System.Security.Principal.SecurityIdentifier.IsAccountSid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。