ASP.net Razor and Form views to show Integrated Windows Authentication details.
<!-- ASP.NET Razor View -->
<!-- ======================================================================= -->
@using System.Security.Principal
@using System.Threading
@model dynamic
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Windows Authentication Details</title>
</head>
<body>
<h2>Windows Authentication Details</h2>
<h3>User Identity</h3>
<ul>
<li><strong>Name:</strong> @User.Identity.Name</li>
<li><strong>Authentication Type:</strong> @User.Identity.AuthenticationType</li>
<li><strong>Is Authenticated:</strong> @User.Identity.IsAuthenticated</li>
</ul>
<h3>Thread Identity</h3>
<ul>
<li><strong>Identity:</strong> @Thread.CurrentPrincipal.Identity.Name</li>
</ul>
@{
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
}
@if (windowsIdentity != null)
{
<h3>Windows Identity</h3>
<ul>
<li><strong>Name:</strong> @windowsIdentity.Name</li>
<li><strong>Authentication Type:</strong> @windowsIdentity.AuthenticationType</li>
<li><strong>Is Authenticated</strong> @windowsIdentity.IsAuthenticated</li>
<li><strong>Is Anonymous:</strong> @windowsIdentity.IsAnonymous</li>
<li><strong>Is Guest:</strong> @windowsIdentity.IsGuest</li>
<li><strong>Is System:</strong> @windowsIdentity.IsSystem</li>
<li><strong>Impersonation Level:</strong> @windowsIdentity.ImpersonationLevel.ToString()</li>
</ul>
}
@if (windowsIdentity != null)
{
<p><strong>Group Membership:</strong></p>
<ul>
@if (windowsIdentity.Groups != null)
{
foreach (var groupId in windowsIdentity.Groups)
{
var groupName = groupId.Translate(typeof(NTAccount));
<li>@groupName <small>(@groupId)</small></li>
}
}
</ul>
}
</body>
</html>
<!-- ASP.NET Forms Page -->
<!-- ======================================================================= -->
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Security.Principal" %>
<%@ Import Namespace="System.Threading" %>
<!DOCTYPE html>
<html>
<head>
<title>Windows Authentication Details</title>
</head>
<body>
<h2>Windows Authentication Details</h2>
<h3>User Identity</h3>
<ul>
<li><strong>Name:</strong> <%= User.Identity.Name %></li>
<li><strong>Is Authenticated:</strong> <%= User.Identity.IsAuthenticated %></li>
<li><strong>Authentication Type:</strong> <%= User.Identity.AuthenticationType %></li>
</ul>
<h3>Thread Identity</h3>
<ul>
<li><strong>Identity:</strong> <%= Thread.CurrentPrincipal.Identity.Name %></li>
</ul>
<h3>Windows Identity</h3>
<% WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent(); %>
<ul>
<li><strong>Name:</strong> <%= windowsIdentity.Name %></li>
<li><strong>Authentication Type:</strong> <%= windowsIdentity.AuthenticationType %></li>
<li><strong>Is Authenticated:</strong> <%= windowsIdentity.IsAuthenticated %></li>
<li><strong>Is Anonymous:</strong> <%= windowsIdentity.IsAnonymous %></li>
<li><strong>Is Guest:</strong> <%= windowsIdentity.IsGuest %></li>
<li><strong>Is System:</strong> <%= windowsIdentity.IsSystem %></li>
<li><strong>Impersonation Level:</strong> <%= windowsIdentity.ImpersonationLevel.ToString() %></li>
</ul>
<p><strong>Group Membership:</strong></p>
<ul>
<% foreach (var groupId in windowsIdentity.Groups)
{
var groupName = groupId.Translate(typeof(NTAccount));
Response.Write("<li>" + @groupName + "</li>");
} %>
</ul>
</body>
</html>