?
Solved

Index was outside the bounds of the array.

Posted on 2009-04-17
5
Medium Priority
?
1,945 Views
Last Modified: 2012-05-06
i am trying to get the username from active directory using the following code, the code works with no problem when in VS 2008 development server, but when i transfer it to our webserver
IIS 6 , windows 2003 , .net 3.5 SP1 ... it gives this error

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
   _Default.Page_Load(Object sender, EventArgs e) +279
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082

here is my code, very very simple

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.DirectoryServices;
using System.Security.Permissions;
using System.Data.SqlClient;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String LDAPpath = "LDAP://192.168.0.2/";
        System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
        string[] a = Context.User.Identity.Name.Split('\\');
        System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
        string Name = ADEntry.Properties["FullName"].Value.ToString();
        Literal name = new Literal();
        name.Text = "Hello " + Name + ",";
        PlaceHolder1.Controls.Add(name);
    }
}

Open in new window

0
Comment
Question by:Raul77
  • 3
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 2000 total points
ID: 24172476
Line 23, right?

Context.User.Identity.Name is not returning something that is splitting on '\\' as expected.  You'll need to dump Context.User.Identity.Name and see what it's actually giving you.  If looking at it doesn't help, please post the result & I'll have a look too.


0
 

Author Comment

by:Raul77
ID: 24172510
mmm you are right ... its blank !!! nothing is there .... but when i run it on my local machine its
Domain\username

????
0
 

Author Comment

by:Raul77
ID: 24172622
ok i played with it, in IIS under Directory Security i un-checked anonymous login and checked Digest authentication
now when i go to the site it ask for my user/pass when i put it it shows

Domain\username

is there anyway it could do this without user entering user/pass ? as long as they are behind their computer in the domain, it shouldnt ask for user/pass. (thats my goal).

Thanks,
0
 

Author Comment

by:Raul77
ID: 24172680
all working now, i had to re-start IIS and working now ...
0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 24172738
>>is there anyway it could do this without user entering user/pass ? as long as they are behind their computer in the domain, it shouldnt ask for user/pass.

Yeah, that's the other authentication type ... Integrated IIRC.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question