I have a test application created in VS 2005 as an ASP.NET application. MSDN says that
By default, ASP.NET does not use impersonation, and your code is executed using the ASP.NET application process ID.
And I have the following web.config
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true" defaultLanguage="c#" />
<authentication mode="Windows"/>
<identity impersonate="false"/>
</system.web>
</configuration>
So, it seems that impersonation is disabled in the same way as the proposed article .
My aspx is empty by default, and codebehind
namespace TestWebapp
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(String.Format("Before1: Current Princupal = {0}", Thread.CurrentPrincipal.Identity.Name));
WindowsImpersonationContext ctx = WindowsIdentity.Impersonate(IntPtr.Zero);
try
{
int a = 0;
System.Diagnostics.Debug.WriteLine(String.Format("After: Current Princupal = {0}", Thread.CurrentPrincipal.Identity.Name));
} finally
{
ctx.Undo();
}
}
}
}
When I reload the page, I get the following debug output:
[5288] Before1: Current Princupal = DOMAIN \ User [5288] After: Current Princupal = DOMAIN \ User
Result matches
<identity impersonate="false"/>
- NETWORK SERVICE .
, web.config, , w3p.exe NETWORK SERVICE.
?
!
@Edit: , !
$user , , : , NT AUTHORITY\NETWORK SERVICE, DOMAIN\User WindowsIdentity.Impersonate(IntPtr.Zero) "No Token. Thread ". .
Thread.CurrentPrincipal.Identity.Name HttpContext.Current.User.Identity.Name - DOMAIN\User .
@Edit: , Thread.CurrentPrincipal HttpContext.Current.User :
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
HttpContext.Current.User = Thread.CurrentPrincipal;
, , . sharepoint shared services, , .