2014-12-13 79 views
-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不再運作的原因。我在大量的其​​他項目中使用它,並希望看看是否可以在不改變每個項目中的行的情況下解決問題。

+0

什麼是'Request.ServerVariables [ 「LOGON_USER」]的值爲'到底是什麼?你調試了你的代碼嗎? – 2014-12-13 15:33:15

+0

錯誤說明。我認爲你的用戶名不超過7個字符 – Codeek 2014-12-13 15:34:14

+0

@SonerGönül該值爲NULL,我不知道爲什麼當它在2010年拉我的用戶名時,如果我現在運行它。 – techora 2014-12-13 17:20:15

回答

相關問題