-1

First line generating an exception when run at remote server. No error when running the code via IIS Express at my development notebook.

if (Session["LdapData"] == null) {
  // do something 
}

Exception:

[ArgumentOutOfRangeException: Der Index lag außerhalb des Bereichs. Er darf nicht negativ und kleiner als die Sammlung sein. Parametername: index] System.Collections.ArrayList.get_Item(Int32 index) +14539412 System.DirectoryServices.ResultPropertyValueCollection.get_Item(Int32 index) +93

Microsoft does it exactly the same way: https://msdn.microsoft.com/de-de/library/03sekbw5(v=vs.100).aspx

if (Session["City"] == null) 
    // No such value in session state; take appropriate action.

Any ideas for debugging?

Edit: Also read this articles, but didn´t get the point:

Difference between Session and HttpContext.Current.Session

How to use sessions in an ASP.NET MVC 4 application?

  • You showed too little code, so no one can easily guess what is `Session` in the snippet, except the fact that it is of `System.DirectoryServices.ResultPropertyValueCollection` type. I assume you ran an AD query and get such a result, then running on IIS Express and IIS are different because different credentials are used, https://blog.lextudio.com/web-application-differences-in-visual-studio-and-iis-60fec7e311b3 As a result, some queries can return different results, as IIS pool identity might not have the permissions on all properties. – Lex Li Oct 10 '18 at 16:57
  • if (System.Web.HttpContext.Current.Session["LdapData"] == null) {} "LdapData" is just a variable name I created. – Till Patzig Oct 11 '18 at 07:26

1 Answers1

0

The exception was not related to the quoted line. Don´t know why, but the displayed line number generated by the IIS is incorrect. Indeed the exception was caused by an ldap query some lines below in the code.