Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2009, 05:32 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default Index was outside the bounds of the array

When running an application a web page I get following error:

Index was outside the bounds of the array.
[IndexOutOfRangeException: Index was outside the bounds of the array.]
Default_aspx.Page_Load(Object sender, EventArgs e) +422

Code:
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
ViewState("InitialSort1") = Boolean.TrueString = True
button2.Visible = False
Calendar1.Visible = False
TextBox1.Text = Session("Saved_JobNumber")
TextBox2.Text = Session("Saved_Text")
Else
ViewState("@User_Id") = UCase(Request.ServerVariables("LOGON_USER")).Split("\")(1)
End If
End Sub
Now, this works on my local machine, but not when published to the web server. If I remove/comment out following line:

ViewState("@User_Id") = UCase(Request.ServerVariables("LOGON_USER")).Split ("\")(1)

it works fine.
 
Old February 12th, 2009, 05:58 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default *WHICH* array???

You need to DEBUG. Find out WHICH array it is complaining about.

I *SUSPECT* that in the line
Code:
ViewState("@User_Id") = UCase(Request.ServerVariables("LOGON_USER")).Split  ("\")(1)
it is complaining about the array created by the SPLIT. It is basically saying there isn't any "\" character in the LOGON_USER server varaible and so the array created by SPLIT has only one element (element ZERO) and so of course trying to use (1) is outside the bounds.

You could easily find this out by breaking that line into multiple pieces and then using the DEBUGGER (yes, it works well) to step through each piece and check what is going on.

Example:
Code:
Dim logonuser = UCase(Request.ServerVariables("LOGON_USER"))
' put a breakpoint here.  Look at value of logonuser.  Does it have a \ in it???
Dim chunks As String() = logonuser.Split("\")
Dim chunkcount As Integer = UBound(chunks)
If chunkcount > 0 Then
    ViewState("@User_Id") = chunks(1)
Else
    ... what do you do when no \ in LOGON_USER ???
End If
 
Old February 13th, 2009, 10:35 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Smile

Hi Old Pedant,

Thank you for a very good explanation.

The reason it did not work (doing the split) was that for this site, the authenitication method was set to Enable Anonymouss Access = True (the other sites that are working it is set to false). I did the debug and found the problem.

Again I very much appreciate your help......





Similar Threads
Thread Thread Starter Forum Replies Last Post
Index was outside the bounds of the array ECPcenter ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2008 04:55 AM
Array Bounds mjhoagland Classic ASP Basics 9 September 28th, 2006 09:01 AM
Index was outside the bounds of the array dba123 Reporting Services 0 March 6th, 2006 11:25 AM
index outside bounds of array error? barmanvarn BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 February 17th, 2005 03:25 PM
System.Index out of Bounds chiraagb ADO.NET 3 June 10th, 2004 12:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.