VS2010 WEB取得域帐号功能,在XP上可以正常运行且不会出现问题,在Windows2008上运行时代码“_systemName = _systemName.Substring(4);”出现错误,提示为“startIndex cannot be larger than length of string.”。代码:
string _systemName;
int _length;
_systemName = HttpContext.Current.Request.ServerVariables["USER"];
_length = _systemName.Length;
_systemName = _systemName.Substring(4);
string _systemName;
int _length;
_systemName = HttpContext.Current.Request.ServerVariables["USER"];
_length = _systemName.Length;
_systemName = _systemName.Substring(4);
断点调试下_systemName.Length;在XP和Windows2008下分别看看_systemName的长度是多少,估计在Windows2008下没有取到域帐号,所以在用_systemName.Substring(4)截取字符串的时候才出的错