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