I have the following pattern throughout my application, creating a Server object using impersonation to retrieve data.
public ActionResult Index(){
Index model = new Index();
using (new Impersonation("domain", "username", "password")){
Server server = new Server("serverInstance");
model.ApplicationList = server.GetApplications();
model.Details = server.GetDetails();
}
}
I was wondering if this can be translated into a wrapper function. So it can be called the following way
SecureManager.PerformOperation("domain", "username", "password", server => server
{
server.GetApplications();
server.GetDetails();
....
});
The goal is to only use the Server object within the Impersonation block.