Run code as different user in c#
In our application, some tasks might need to be run as different user or as administrator. Below you can find a simple and effective solution for this purpose.
Simple Impersonation Library is a library which lets you to impersonate any user with its login credentials. From NuGet package, you can get this library.
Simple Impersonation Library is a library which lets you to impersonate any user with its login credentials. From NuGet package, you can get this library.
Then you can implement your code inside a section as below:
using (SimpleImpersonation.Impersonation.LogonUser("domainname", "Username", "password", SimpleImpersonation.LogonType))
{
// Your running code as this user
}
No comments:
Post a Comment