C# 使用身份验证模式获取intranet中的域\用户=";表格;

C# 使用身份验证模式获取intranet中的域\用户=";表格;,c#,asp.net,iis,forms-authentication,C#,Asp.net,Iis,Forms Authentication,我必须在intranet网络中安装ASP.NET站点。 我使用的是身份验证模式=表单”。 在我的页面中,我需要连接用户的域\用户 我关注了这篇文章: 但它不起作用。 My web.config有: <identity impersonate="true"/> <authentication mode="Forms" > <forms name="login" loginUrl="~/Login.aspx" defaultUrl="~/Defa

我必须在intranet网络中安装ASP.NET站点。 我使用的是身份验证模式=表单”。 在我的页面中,我需要连接用户的域\用户

我关注了这篇文章:

但它不起作用。 My web.config有:

 <identity impersonate="true"/>
<authentication mode="Forms" >
          <forms name="login" loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx" timeout="30000" />
</authentication>  
<authorization>      
  <deny users = "?" />
  <!-- This denies access to the Anonymous user -->
  <allow users ="*" />
  <!-- This allows access to all users -->
</authorization>
我该怎么办


谢谢

如果您启用了匿名访问,则网站访问者都将模拟IUSR_MachineName帐户(或您配置为匿名帐户的任何帐户)


您需要禁用匿名访问,这样网站将强制用户使用其凭据进行身份验证,以便这些凭据可以在您的ASP.NET页面中使用。否则,服务器不知道当前用户是谁。

您不使用
mode=“windows”有何原因“
?这样做会将windows用户名放入
HttpContext.Current.User.Identity.Name
。因为如果我使用mode=“windows”,如果没有登录,用户必须插入用户名和密码。如果用户已登录,我希望获取用户名,否则不执行任何操作使用窗体身份验证时无法获取Windows用户名。您必须使用Windows身份验证,或者让用户通过一个单独的站点,该站点具有Windows身份验证,可以将用户的Windows用户名传回表单身份验证站点(直接或通过查找值传回)
-Enable anonymous access
-Integrated windows authentication