using impersonation in code

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();
 
S

Stefan

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.
 
G

Guest

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top