【问题标题】:ASPX works locally but not on serverASPX 在本地工作,但不在服务器上
【发布时间】:2012-10-09 14:39:55
【问题描述】:

我已经在服务器上上传了一个 web 项目。

虽然它在我进行开发的本地电脑上运行顺利,但它根本没有在服务器上运行。据我所知,空数据集存在问题(从 SQL 数据库中获取数据)。同样,在本地运行 aspx 时,一切正常。我在错误日志中看到的另一个问题是它指向我的本地驱动器“D:...” 它不应该指向服务器地址吗?

错误。

There is no row at position 0.

Exception Details: System.IndexOutOfRangeException: There is no row at position 0.

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: There is no row at position 0.]
   System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +2474798
   System.Data.DataRowCollection.get_Item(Int32 index) +21
   WEB.Default.Page_Load(Object sender, EventArgs e) in D:\dev\Visual Studio\Temp\WEB\Default.aspx.cs:59
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

有什么想法吗?我使用 VS2010 的发布工具,它成功上传到服务器。但它不起作用。

我不明白的另一件事是,如果我在页面加载中有 try/catch,为什么网页会发送此错误。如果有错误,它会设置一个带有友好消息的标签。

谢谢。

编辑

这是页面加载代码。

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                Session["FlagOpen"] = false;
                var windowsIdentity = WindowsIdentity.GetCurrent();
                if (windowsIdentity != null)
                {
                    var userName = windowsIdentity.Name;
                    userName = Regex.Replace(userName, ".*\\\\(.*)", "$1", RegexOptions.None);
                    var ds = _objUser.GetRanking(userName);
                    var ranking = ds.Tables[0].Rows[0][1].ToString();
                    _objPersona.Ranking = ranking;
                    _objPersona.UserName = userName;
                    _objPersona.RealName = ds.Tables[0].Rows[0][0].ToString();
                    Session["User"] = _objPersona;
                    LblUserName.Text = ds.Tables[0].Rows[0][0].ToString();
                    ds = _objUser.GetFAQ(userName);
                    var cant = ds.Tables[0].Rows.Count;                        
                }
                else
                {
                    BtnAbrirBandeja.Enabled = false;
                    LblUserName.Text = "Not allowed.";
                }
            }
        }
        catch (Exception)
        {
            LblWarnings.Text = "Error. Please contact sysadmin.";
            throw;
        }

    }

编辑 2。

页面继续在本地工作。但不在服务器上。它抛出指向本地文件夹的原始错误(当它已经从服务器上载并运行时)。 DataSet 为空是 Web 无法与 SQL 服务器通信的结果。因此错误。 基本上,它在调试时运行正常,但在服务器上运行不正常。

有什么想法吗?谢谢。

【问题讨论】:

  • 没有任何来源,很难分辨。
  • 愚蠢的问题,但是可以从服务器访问数据库吗?
  • @PhonicUK 如果需要,我可以向您展示 Page_Load,但由于它(本地)有效,我认为这将是本地/服务器 aspx 内容的更普遍错误。
  • @Jay 我知道来自同一台服务器的其他 webprojects 访问那个特定的 SQL 数据库,所以我假设是的。不过会检查。
  • 这个建议很糟糕,抱歉。

标签: c# asp.net visual-studio-2010


【解决方案1】:

在尝试从数据集中访问 element 之前,您需要测试数据集的 null,因此会出现错误消息:

if (ds!=null)
 { 
  //continue and access the dataset
 }
else
 {
  //you didn't get any data or ds is simply null (result set is null)
 }

您也误用了var 关键字,您不需要将var 用于字符串和数据集等简单类型。

【讨论】:

  • 乔恩。除了 ds 为 null 和 var 的。你知道为什么错误指向我的本地开发文件夹吗?该项目已经上传到服务器......我有点迷失了。
  • 也许您没有正确部署解决方案?这是一个奇怪的问题,我想我以前见过,只是不记得它是如何解决的。如果您在我将其发回此处之前找到答案,那么我们都知道!
  • 这是匿名登录之类的。该项目无法获得 Windows/域,所以这就是火花。谢谢
【解决方案2】:

无论出于何种原因,您的数据无法访问或不存在:

[IndexOutOfRangeException: There is no row at position 0.]

var ranking = ds.Tables[0].Rows[0][1].ToString();

在执行该行之前,您需要检查ds.Tables.length(或计数)。

【讨论】:

    【解决方案3】:

    可能是在您的本地计算机上运行时,它正在从本地服务器获取数据,现在它从您的服务器数据库引擎获取数据..那里的表可能是空的,或者那里可能不存在表.. 检查您的数据集获取方法是否有任何错误..您的 try catch 可能隐藏了该错误..

    你的另一部分问题:

    它会抛出该异常,因为您的 catch 块有一个“throw”语句,该语句将通过带有所有内部异常详细信息的 catch 块捕获的相同错误..

    注意:如果你写 捕捉(异常前) {throw ex;}

    内部异常细节将会丢失...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      • 2021-10-01
      相关资源
      最近更新 更多