即使我注释掉发生错误的行,我仍然收到上述错误消息。知道是什么原因造成的吗?我尝试用测试值重写这些行,但仍然遇到相同的错误。
这在调试模式下工作得很好,只有在部署中才会出现。
原始代码:
Line 21: string domain, username;
Line 22: string text = Page.User.Identity.Name;
Line 23:
Line 24: domain = text.Substring(0, text.IndexOf("\\"));
Line 25: username = text.Substring(text.IndexOf("\\") + 1, text.Length - text.IndexOf("\\") - 1);
Source File: F:\<file path>\Default.aspx.cs Line: 23
测试代码(同样的错误):
Line 21: string domain, username;
Line 22: //string text = "TEST"; // Page.User.Identity.Name;
Line 23: // this line is blank
Line 24: domain = "TEST"; //text.Substring(0, text.IndexOf("\\"));
Line 25: username = "TEST"; // text.Substring(text.IndexOf("\\") + 1,
Source File: F:\<file path>\Default.aspx.cs Line: 23
这是堆栈跟踪(如果有帮助的话):
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +12681546
Insufficiencies._Default.Page_Load(Object sender, EventArgs e) in F:\<file path>\Default.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048