问题描述
HttpUsrName =(HttpContext.Current.User.Identity.Name.ToString()。Split('\\')[1]);
分割硬编码值(Domain \\UserName)工作原理
但代码行上面给出错误
System.ArgumentOutOfRangeException:startIndex不能大于字符串的长度。参数名称:startIndex
我已经通过谷歌获得了几个解决方案,但仍未获得任何解决方案。
任何人都可以获得任何解决方案。
HttpUsrName = (HttpContext.Current.User.Identity.Name.ToString().Split('\\')[1]);
splitting of hardcoded value (Domain\\UserName)works
but above code line giving error
"System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex"
I have gone through google for several solution but still not get any solution.
Any solution from anyone will be appreciate.
推荐答案
string[] parts = HttpContext.Current.User.Identity.Name.ToString().Split('\\');
if (parts.Length == 2) {
HttpUsrName = parts[1];
}
else {
HttpUsrName = "Problem in username parsing from http context";
}
这篇关于得到以下错误“System.ArgumentOutOfRangeException:startIndex不能大于字符串的长度。参数名称:startIndex"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!