Click here to Skip to main content
15,886,110 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:

C#
app.Run(async (context) =>
{
    try
    {
        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());
    }
});
Posted
Updated 11-Apr-23 22:17pm
v2
Comments
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