基本的に、ログインしているユーザーになりすまして、Web アプリケーションからネットワーク共有リソースにアクセスしようとしています。私はこの例 [ http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity]に従いました。ここでは、ライターはキャストの失敗について言及していません。そのキャストを行ったとき、キャストを行うことができないというランタイム例外が発生しました。誰もこの種の問題を経験したことがありますか?
ガイダンスや提案は大歓迎です!
ありがとうございました
WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity;
WindowsImpersonationContext ctx = null;
try
{
// Start impersonating
ctx = winId.Impersonate();
// Now impersonating
// Access resources using the identity of the authenticated user
}
// Prevent exceptions from propagating
catch
{
}
finally
{
// Revert impersonation
if (ctx != null)
ctx.Undo();
}
// Back to running under the default ASP.NET process identity