Click here to Skip to main content
15,745,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my requirement is to copy the file from production server path to staging server path

What I have tried:

app.Run(async (context) =>
        var user = System.Security.Principal.WindowsIdentity.GetCurrent();

        await context.Response
            .WriteAsync($"User: {"registry:HKLM\\SOFTWARE\\spg\\identity\\ASPNET_SETREG,userName"}\tPassword: {"registry:HKLM\\SOFTWARE\\spg\\identity\\ASPNET_SETREG,password"}\n");

        WindowsIdentity.RunImpersonated(user.AccessToken, () =>
            var impersonatedUser = WindowsIdentity.GetCurrent();
            var message =
                $"User: {impersonatedUser.Name}\t" +
                $"State: {impersonatedUser.ImpersonationLevel}";

            var bytes = Encoding.UTF8.GetBytes(message);
            // context.Response.Body.Write(bytes, 0, bytes.Length);
    catch (Exception e)
        await context.Response.WriteAsync(e.ToString());
Updated 11-Apr-23 22:17pm
Richard Deeming 12-Apr-23 4:18am    
You seem to have forgotten to ask a question. Start by explaining precisely what you are trying to do, what you have tried, and where you are stuck. Include the full details of any errors.

NB: Attempting to impersonate yourself seems a little odd.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900