using impersonation in code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am new to asp.net and am trying to open a word document readonly from the
server. I am not sure how to do that either, but what I tried gave me an
error re: rights. I read the following on impersonation, but got an error
trying it. It is in C# and I translated to vb.net, so perhaps I translated
incorrectly. Could someone show me what to do:

Thanks so much -- below is from the article I mentioned.

To impersonate the authenticating user (User.Identity) only when you run a
particular section of code, you can use the code to follow. This method
requires that the authenticating user identity is of type WindowsIdentity.

System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

//Insert your code that runs under the security context of the
authenticating user here.

impersonationContext.Undo();
 
Did you get a compilation error?
Or an exception at runtime? If so, what exception?

Don't forget to disable anonymous auth in IIS and set the auth in your
web.config to Windows.
 
The error regards the token that I need to set up and further research
indicatated that to set up an anonoymous account was very complicated.

What do you mean by set the auth in the config?
 
Back
Top