Home > front end >  System.IndexOutOfRangeException: Index was outside the bounds of the array application in IIS
System.IndexOutOfRangeException: Index was outside the bounds of the array application in IIS

Time:11-11

when i transported my application (using windows authentication)

User.Identity.Name.Split('\\')[1];   

like above.

Throw error in iis but It works well in local.

System.IndexOutOfRangeException: Index was outside the bounds of the array.

i enabled windows authentication. Where i am wrong?

CodePudding user response:

The only index you're using is 1 so, if that's out of range, then there must only be one element in your array, which means that there are no slashes in the input. What you want is the last element in the array, whether there is one or two elements, so use User.Identity.Name.Split('\\').Last() instead.

  • Related