VS2005でASP.NETアプリケーションとして作成された空のテストアプリがあります。MSDNによると
既定では、ASP.NETは偽装を使用せず、コードはASP.NETアプリケーションのプロセスIDを使用して実行されます。
そして私は次のweb.configを持っています
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" defaultLanguage="c#" />
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<identity impersonate="false"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
したがって、記事が示唆しているように、なりすましは無効になっているようです。
私のaspxはデフォルトで空白で、コードビハインドは
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();
}
}
}
}
ページをリロードすると、次のデバッグ出力が表示されます。
[5288]前1:現在のプリンキュパル= DOMAIN \ User [5288]後:現在のプリンキュパル= DOMAIN \ User
出力はと同じです
<identity impersonate="false"/>
Webサイトはデフォルトのアプリケーションプールを使用し、プールはワーカープロセスにNETWORKSERVICEアカウントを使用するように設定されています。アプリケーションが使用する必要のあるweb.configを使用し、w3p.exeワーカープロセスがネットワークサービスで実行されていることを確認します。
この場合、何が間違っている可能性がありますか?
ありがとう!
@編集:ロブ、ヒントをありがとう!$ userショートカットは、すべてが期待どおりに行われていることを示しています。偽装すると、ユーザーNT AUTHORITY \ NETWORK SERVICEを実行しているプロセスがあり、スレッドにはWindowsIdentity.Impersonate(IntPtr.Zero)の前にDOMAIN\Userがあります。なりすましではありません。」後。ただし、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共有サービスがユーザープロファイルのアクセス許可を管理することに問題がありますが、それは別の質問です。