下面的代码是我得到计算机上的NT账号,
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要描述。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected DataSet ds=new DataSet();

private void Page_Load(object sender, System.EventArgs e)
{
// 在这里放置使用者程序代码以初始化网页
string Auth_users;
string[] logon;
string lname;
Auth_users=Request.ServerVariables["Auth_user"].ToString();
logon=Auth_users.Split('\\');
lname=logon[1].Trim();
this.TextBox1.Text=lname;
string str="select * from elogin1 where nt='"+lname+"'";
SqlConnection Conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"].ToString());
SqlDataAdapter da=new SqlDataAdapter(str,Conn);
da.Fill(ds,"elogin1");
if(ds.Tables["elogin1"].Rows.Count!=0)
{
Response.Write("<script language=javascript>window.location.href='webform2.aspx';</script>");
} }  #region Web Form 设计工具产生的程序代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此为 ASP.NET Web Form 设计工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 此为设计工具支持所必须的方法 - 请勿使用程序代码编辑器修改
/// 这个方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}话
在Web.config中加入的代码是:
      <appSettings>
   <add key="ConnStr" value="Server=10.65.2.80;User id=ieb;Pwd=ieb;Database=cust"></add>
  </appSettings>但是我把该代码移植到公司的服务器上,就会出现这样的错误提示,
'/wangtest' 应用程序中发生服务器错误。 
________________________________________
索引在数组的界限之外。 
描述: 在执行目前 Web 要求的过程中发生未处理的例外情形。请检阅堆栈追踪以取得错误的详细信息,以及在程序代码中产生的位置。 例外详细信息: System.IndexOutOfRangeException: 索引在数组的界限之外。原始程序错误: 
在执行目前 Web 要求期间,产生无法处理的例外状况。如需有关例外状况来源与位置的信息,可以使用下列的例外状况堆栈追踪取得。 堆栈追踪: [IndexOutOfRangeException: 索引在数组的界限之外。]
   WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication1\webform1.aspx.cs:32
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750________________________________________
版本信息: Microsoft .NET Framework 版本:1.1.4322.2300; ASP.NET 版本:1.1.4322.2300

解决方案 »

  1.   

    同意 shrinerain(圣影雨)这句的问题 lname=logon[1].Trim();索引在数组的界限之外。应该是 logon 数组 只有一个元素  在引用前做一下判断吧
      

  2.   

    数组越界了吧!
    Auth_users=Request.ServerVariables["Auth_user"].ToString();
    logon=Auth_users.Split('\\');
    lname=logon[1].Trim();
    因该是这个地方的问题吧!
    logon不一定会有2个元素吧!跟踪一下就知道了!!!!