I am basically trying to access the network share resources from my Web Application by impersonating the logged in user. I followed this example [http://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingbyusingwindowsidentity], here the writer does not mention about the cast failing. When i did that cast, I got the runtime exception that the cast cannot be made. Anyone has gone through this kind of issues before?
Guidance or suggestions are higly appreciated!
Thank you
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
What is really in your
Identity
?? Maybe it's a generic identity or some other identity - not a Windows identity as you assume it is:What's the result here? That might give you more information as to what you're really dealing with here.
Marc
I am not sure what you're trying to do with impersonation so it's hard to tell you exactly how to do it but the User object in your web app is equivelent to a System.Security.Principal.IPrincipal object and not a WindowsPrincipal object.
Likewise, the User.Identity is an IIdentity and not a WindowsIdenity object.
Can you post more about what you're trying to do?