<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FSecurity%2FWindowsIdentity</id>
		<title>Csharp/CSharp Tutorial/Security/WindowsIdentity - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FSecurity%2FWindowsIdentity"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Security/WindowsIdentity&amp;action=history"/>
		<updated>2026-04-30T02:48:28Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Security/WindowsIdentity&amp;diff=6018&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Security/WindowsIdentity&amp;diff=6018&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Security/WindowsIdentity&amp;diff=6019&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Security/WindowsIdentity&amp;diff=6019&amp;oldid=prev"/>
				<updated>2010-05-26T12:17:56Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Determining group identity: WindowsBuiltInRole.PowerUser==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    WindowsIdentity wi = WindowsIdentity.GetCurrent();&lt;br /&gt;
    WindowsPrincipal prin = new WindowsPrincipal(wi);&lt;br /&gt;
    if (prin.IsInRole(WindowsBuiltInRole.PowerUser)) &lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;You are a member of the Power User group&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;You are not a member of the Power User group&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;You are not a member of the Power User group&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get current principal identity name==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
using System.Security;&lt;br /&gt;
using System.Security.Permissions;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {          &lt;br /&gt;
            System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();&lt;br /&gt;
            Thread.CurrentPrincipal = new System.Security.Principal.WindowsPrincipal(wi);&lt;br /&gt;
            Console.WriteLine(wi.Name);&lt;br /&gt;
            Console.WriteLine(Thread.CurrentPrincipal.Identity.Name);&lt;br /&gt;
            PrincipalPermission pp = new PrincipalPermission(null, &amp;quot;Administrators&amp;quot;, true);&lt;br /&gt;
            pp.Demand();&lt;br /&gt;
            PrincipalPermission pp2 = new PrincipalPermission(null, &amp;quot;Users&amp;quot;, true);&lt;br /&gt;
            pp.Union(pp2).Demand();&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                PrincipalPermission pp3 = new PrincipalPermission(null, &amp;quot;Club&amp;quot;);&lt;br /&gt;
                pp3.Demand();&lt;br /&gt;
            }&lt;br /&gt;
            catch (SecurityException e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;You do not have access to the secret club.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get the current identity==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    WindowsIdentity wi = WindowsIdentity.GetCurrent();&lt;br /&gt;
    Console.WriteLine(&amp;quot;Identity information:&amp;quot;);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Authentication Type: {0}&amp;quot;,wi.AuthenticationType);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Is Anonymous: {0}&amp;quot;, wi.IsAnonymous);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Is Authenticated: {0}&amp;quot;, wi.IsAuthenticated);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Is Guest: {0}&amp;quot;, wi.IsGuest);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Is System: {0}&amp;quot;, wi.IsSystem);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Name: {0}&amp;quot;, wi.Name);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Token: {0}&amp;quot;, wi.Token);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Identity information:&lt;br /&gt;
  Authentication Type: NTLM&lt;br /&gt;
  Is Anonymous: False&lt;br /&gt;
  Is Authenticated: True&lt;br /&gt;
  Is Guest: False&lt;br /&gt;
  Is System: False&lt;br /&gt;
  Name: nfex\Joe&lt;br /&gt;
  Token: 1800&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get the current identity and its associated principal==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    WindowsIdentity wi = WindowsIdentity.GetCurrent();&lt;br /&gt;
    &lt;br /&gt;
    WindowsPrincipal prin = new WindowsPrincipal(wi);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Principal information:&amp;quot;);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Authentication Type: {0}&amp;quot;, prin.Identity.AuthenticationType);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Is authenticated: {0}&amp;quot;, prin.Identity.IsAuthenticated);&lt;br /&gt;
    Console.WriteLine(&amp;quot;  Name: {0}&amp;quot;, prin.Identity.Name);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Principal information:&lt;br /&gt;
  Authentication Type: NTLM&lt;br /&gt;
  Is authenticated: True&lt;br /&gt;
  Name: nfex\Joe&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Impersonation==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.IO.IsolatedStorage;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Net.Sockets;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
using System.Security;&lt;br /&gt;
using System.Security.AccessControl;&lt;br /&gt;
using System.Security.Policy;&lt;br /&gt;
using System.Security.Permissions;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        WindowsIdentity identity = WindowsIdentity.GetCurrent();&lt;br /&gt;
        WindowsImpersonationContext context = identity.Impersonate();&lt;br /&gt;
        context.Undo();&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Iterate through the group names to see if the current user is a member of each one==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main (string[] args) &lt;br /&gt;
    {&lt;br /&gt;
        &lt;br /&gt;
        WindowsIdentity identity = WindowsIdentity.GetCurrent();&lt;br /&gt;
        WindowsPrincipal principal = new WindowsPrincipal(identity);&lt;br /&gt;
        &lt;br /&gt;
        foreach (string role in args) &lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;Is {0} a member of {1}? = {2}&amp;quot;, identity.Name, role, principal.IsInRole(role));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Obtain a WindowsIdentity object representing the currently logged on Windows user==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main (string[] args) &lt;br /&gt;
    {&lt;br /&gt;
        &lt;br /&gt;
        WindowsIdentity identity = WindowsIdentity.GetCurrent();&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>