满足使用Request.ServerVariables["REMOTE_USER"]的条件:
1、IIS配置网站的目录安全性取消“启用匿名访问(&A)”
2、启用 “集成 Windows 身份验证(&N)”
3、web.config中配置<authentication mode="Windows"/>
4、浏览器安全配置自定义级别中,勾选“自动使用当前用户名和密码登录”,或者将网站加入到Intranet组。
5、如果需要使用域账号,需要修改IIS网站为强制NTLM认证方式。可以通过脚本修改,或是直接修改iis6的C:WINDOWSsystem32inetsrvMetaBase.xml文件,在<IIsWebServer 节点中修改NTAuthenticationProviders="NTLM"。IIS5需要使用MetaEdit程序来修改这个属性。
6、脚本方式实现第5项:
IIS7.0
查看NTAuthenticationProviders:
c:windowssystem32inetsrvappcmd list config /section:windowsAuthentication
设置NTAuthenticationProviders:
c:windowssystem32inetsrvappcmd clear config /section:windowsAuthentication
c:windowssystem32inetsrvappcmd set config /section:windowsAuthentication -+providers.[value='Negotiate']
c:windowssystem32inetsrvappcmd set config /section:windowsAuthentication -+providers.[value='NTLM']
使用Appcmd.exe在IIS7.0中禁用Windows验证
1.cd %SystemRoot%System32inetsrv
2.更改设置:
appcmd.exe set config /section:windowsAuthentication /enabled:false
3.查看更改后的设置:
appcmd list config /section:windowsAuthentication
IIS6.0:
查看NTAuthenticationProviders:
cscript adsutil.vbs get w3svc/WebSite/root/NTAuthenticationProviders
设置NTAuthenticationProviders:
cscript adsutil.vbs set w3svc/WebSite/root/NTAuthenticationProviders "Negotiate,NTLM"
IIS5.0或5.1
查看NTAuthenticationProviders:
cscript adsutil.vbs get w3svc/NTAuthenticationProviders
设置NTAuthenticationProviders:
cscript adsutil.vbs set w3svc/NTAuthenticationProviders "Negotiate,NTLM"