I am writing a web application that works with exchange, and so needs to impersonate an account that has admin rihgts to Exchange. This account is specified by the user on setup. What is the best way to get impersonation to use this account, obviously hard-coding this into the web.config won’t work as it needs to be able to change, but I’m not sure of the best way to do it. Also, I actually only need to run as this administrative user for 1 class, is it possible to only impersonate for some methods?
Share
I posted an answer on using impersonation to access a network file share, but it should work for you as well. It includes source for a c# class that can be used to manage the begin/end of impersonation and can be used by any class or method.
The source provided does assume that you are storing the username and password in the web.config.
See the original question and answer for more details.