-1
过去几年我一直在使用Visual Studio 2010,但今天我们被要求更新到2013.我去打开我现有的项目,它以前没有任何问题,但现在抛出以下错误:Request.ServerVariables无法在VS 2013中工作
string logon_user = Request.ServerVariables["LOGON_USER"].Substring(7);
上的任何想法如何解决此问题:
A first chance exception of type 'System.ArgumentOutOfRangeException'
occurred in mscorlib.dll
Additional information: startIndex cannot be larger than length of string.
此错误是在这行代码触发?经过一番研究,我发现了一个简单的解决方法使用此行:
string logon_user = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(7);
但我更感兴趣的是找出为什么Request.ServerVariables不再运作的原因。我在大量的其他项目中使用它,并希望看看是否可以在不改变每个项目中的行的情况下解决问题。
什么是'Request.ServerVariables [ “LOGON_USER”]的值为'到底是什么?你调试了你的代码吗? – 2014-12-13 15:33:15
错误说明。我认为你的用户名不超过7个字符 – Codeek 2014-12-13 15:34:14
@SonerGönül该值为NULL,我不知道为什么当它在2010年拉我的用户名时,如果我现在运行它。 – techora 2014-12-13 17:20:15