如何确定用户是从 Internet 还是 Intranet 访问我的应用程序?
我对 IIS 服务器变量的来源和安全性感到非常困惑。 http://msdn.microsoft.com/en-us/library/ms524602.aspx 例如,远程用户的 Request.ServerVariables["AUTH_USER"] 是否为空?
此外,http: //msdn.microsoft.com/en-us/library/system.environment.userdomainname.aspx上有关 Environment.UserDomainName 的文档 让我认为可以通过将计算机名称命名为域来进行游戏我正在检查的名字
理想情况下,我只想...
if ( [ ... user is not remote ... ] && Enironment.UserDomainName == "TargetLocalDomainName" )
var username = Environment.UserName;
PrepareLocalUserSession(username);
RedirectToHomePage();
}
//else
[... redirect to remote login page ...]
所以我的问题是如何确定用户是否来自远程目的地?如果可能的话,我强烈希望使用比 IP 检查更简单的东西。
谢谢
编辑
我认为我上面的方法太可怕了,我想发布一个理智的方法
var hostAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
bool localUser = hostAddress.StartsWith("192.") | hostAddress.StartsWith("10.") | hostAddress.StartsWith("172.") || HttpRequest.Current.Request.IsLocal;
string username = Request.ServerVariables["LOGON_USER"].split( new char[]{"/"})[0];
string domain = Request.ServerVariables["LOGON_USER"].split( new char[]{"/"})[1];
if( localUser && domain == "TargetLocalDomainName" ){
PrepareLocalUserSession(username);
RedirectToHomePage();
}
//else
[... redirect to remote login page ...]