在模仿和模仿代码后面的ASP.NET之后,让IIS用户



我在网站中使用模仿,我需要将每个请求记录到网站上,因此也需要用户名,我认为我们可以在服务器变量中获取此请求,但是Auth_UserLogOn_User返回空字符串。在模仿和模仿之后,如何获得用户名?有人有任何想法吗?

使用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 SERVERASPNET
After Impersonation TestAccount
After undo Impersonation SERVERASPNET

相关内容

最新更新