0
내 사이트에서 가장을 사용하며 각 요청을 사이트에 기록해야하므로 사용자 이름도 필요합니다. 서버 변수, 그러나 Auth_User
및 LogOn_User
은 빈 문자열을 반환합니다. 명의를 도용 한 후에 가장 할 수있는 사용자 이름은 어떻게 얻을 수 있습니까? 어떤 아이디어가 있습니까?코드에서 ASP.NET으로 가장하여 가장을 사용하기 전에 IIS 사용자 가져 오기
내 사이트에서 가장을 사용하며 각 요청을 사이트에 기록해야하므로 사용자 이름도 필요합니다. 서버 변수, 그러나 Auth_User
및 LogOn_User
은 빈 문자열을 반환합니다. 명의를 도용 한 후에 가장 할 수있는 사용자 이름은 어떻게 얻을 수 있습니까? 어떤 아이디어가 있습니까?코드에서 ASP.NET으로 가장하여 가장을 사용하기 전에 IIS 사용자 가져 오기
사용 HttpContext.Current.User.Identity
WindowsIdentity wId = (WindowsIdentity)HttpContext.Current.User.Identity;
WindowsIdentity wIdb4 = WindowsIdentity.GetCurrent();
string name = wIdb4.Name;
Response.Write("Before impersonation"+name +"<br>");// <-- Writes ASPNET Account
//Till this line,code is executed in the context of worker process
WindowsImpersonationContext wIdCon = wId.Impersonate();
WindowsIdentity wIdafter = WindowsIdentity.GetCurrent();
name = wIdafter.Name;
Response.Write("After Impersonation " + name + "<br>");// <-- writes Logged in user
//Run in the context of logged authenticated user, do your //operations that require impersonation
wIdCon.Undo();
WindowsIdentity wIdafterUndo = WindowsIdentity.GetCurrent();
name = wIdafterUndo.Name;
Response.Write("After undo Impersonation " + name + "<br>");
OUTPUT
Before impersonation SERVER\ASPNET
After Impersonation TestAccount
After undo Impersonation SERVER\ASPNET