我试图从WindowsIdentity应用程序的调用方获得当前的ASP.Net,而不进行模拟。
在阅读了一些文章之后,我的设置是:
出于测试目的,我编写了以下日志语句
m_techLogger.Warn(string.Format("Request[LOGON_USER] {0}", Request["LOGON_USER"]));
m_techLogger.Warn(string.Format("Request.LogonUserIdentity {0}", Request.LogonUserIdentity.Name));
m_techLogger.Warn(string.Format("HttpContext.Current.User.Identity {0}", HttpContext.Current.User.Identity.Name));
m_techLogger.Warn(string.Format("WindowsIdentity.GetCurrent() {0}", WindowsIdentity.GetCurrent().Name));此语句返回以下内容
2015-04-23 10:47:19,628 [7] WARN - Request[LOGON_USER] DOMAIN\User
2015-04-23 10:47:19,681 [7] WARN - Request.LogonUserIdentity NT AUTHORITY\SYSTEM
2015-04-23 10:47:19,681 [7] WARN - HttpContext.Current.User.Identity NT AUTHORITY\SYSTEM
2015-04-23 10:47:19,681 [7] WARN - WindowsIdentity.GetCurrent() NT AUTHORITY\SYSTEM据我所知,WindowsIdentity.GetCurrent().Name返回系统用户。我不明白为什么来自Request.LogonUserIdentity和RequestLOGON_USER的输出是不同的。我需要来自用户的WindowsIdentity对象,其名称由RequestLOGON_USER返回。
谁能给我指明正确的方向?
发布于 2018-04-04 13:16:40
请求“LOGON_USER”只是客户端发送到服务器的身份验证头。这意味着它是向服务器发送请求的客户端的登录名。除非激活模拟,否则将不会根据activate验证此登录名。更多信息在这里:https://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx
现在,如果不使用模拟,那么您就会陷入困境。您可以根据服务器上的AD检查请求“LOGON_USER”中的用户。但我不建议你这么做。因为敌对的客户端可以发送该字段中的任何用户名,如果存在该用户,则可以登录到您的服务器上。
正确的方法是启用模拟,使用AD组允许用户执行服务现在正在做的事情,只需将其添加到IIS配置中即可激活。
<configuration>
<system.web>
<identity impersonate="true"/>
</system.web>
</configuration>但是,如果您真的不能使用模拟,您可以通过使用Win32 API模拟一个服务帐户来攻击自己。如果您想自己这样做,下面是Microsoft https://msdn.microsoft.com/en-us/library/chf6fbt4.aspx和https://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx的示例。
或者您可以在这里找到一个很好的包装器:How do you do Impersonation in .NET?
使用它就像这样简单:
using (new Impersonation(domain, username, password))
{
// probably connecting to some bad 3rd party stuff that needs a very specific access.
}现在,我不知道你做这件事的实际原因,我希望这能帮助你在这条路上走得更远,只有在绝对必要的情况下才能这样做。
发布于 2018-04-04 13:03:55
当我尝试同样的,我得到
Request.LogonUserIdentity.Name "DOMAIN\\accountname" (no capital letter)
Request["LOGON_USER"] "DOMAIN\\Accountname" (capital letters)为了在我们的asp.net应用程序中获得当前用户,我使用这一行代码
User.Identity.Name这有什么用吗?
发布于 2018-04-04 17:06:00
System.Web.HttpContext.Current.User.Identity.Name
获取或设置当前HTTP请求的安全信息。(在您的网站上登录的用户名称)
Request.ServerVariables
获取Web服务器变量的集合。
Request属性提供对HttpRequest类的属性和方法的编程访问。因为ASP.NET页面包含对System.Web命名空间(其中包含HttpContext类)的默认引用,所以您可以在.aspx页面上引用HttpRequest的成员,而无需使用对HttpContext的完全限定类引用。
Conclussion都可以工作到相同的地方,但是,通过Request.ServerVariables,您可以动态地迭代整个集合。
例如:
int loop1, loop2;
NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Key: " + arr1[loop1] + "<br>");
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++) {
Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");
}
}https://stackoverflow.com/questions/29828567
复制相似问题