【问题标题】:500 error; not specific enough500错误;不够具体
【发布时间】:2013-10-03 17:12:05
【问题描述】:

我正在使用 Microsoft Visual Web Express 2012 for Web,并且一直在通过 Firefox 进行测试。

当我终于让它工作时,我开始尝试 Chrome 和 IE,但在这两种浏览器上,它都会在一个小窗口中报告 500 内部服务器错误。 html 加载正常。我相信这是因为我的网站在选项卡小部件中加载了数据库信息。重新检查 Firefox;看起来不错。重新检查 Chrome 和 IE;同样的错误。

现在可能很明显了,但是我已经注释掉了 ajax 代码并且 IE 和 Chrome 没有报告 500 问题。

我不知道如何找到有关此一般错误的更多详细信息。我试过了

  <system.webServer>
    <httpErrors errorMode="Detailed" />
    <asp scriptErrorSentToBrowser="true"/>
</system.webServer>
<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" />
</system.web>

在我的 web.config 中,但该窗口仅显示 500。我还尝试取消选中“显示友好的 HTTP 错误消息”和“禁用脚本调试 (IE) 和 (其他)”。我不确定会发生什么,但 500 消息没有改变。

我确实注意到 Firefox 在从数据库加载时确实显示出奇怪的延迟,但加载后那里的所有数据都很好。

这是有问题的代码。

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Text;
using System.Web.Script.Services;

/// <summary>
/// Summary description for serverAttempt2
/// </summary>
[WebService(Namespace = "http://idontcare.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[ScriptService]

public class serverAttempt2 : WebService
{
  [WebMethod]
  public string GetCustomer(string CustomerID)
  {
    string response = "<p>No customer selected</p>";
    string connect = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=personnet;Integrated Security=Yes;";
    string query = "SELECT TOP 200 * FROM personnet.dbo.accordionTest";
    if (CustomerID != null && CustomerID.Length == 8)
    {
      StringBuilder sb = new StringBuilder();
      using (SqlConnection conn = new SqlConnection(connect))
      {
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
          cmd.Parameters.AddWithValue("CustomerID", CustomerID);
          conn.Open();
          SqlDataReader rdr = cmd.ExecuteReader();
          if (rdr.HasRows)
          {
            while (rdr.Read())
            {
                sb.Append("Hi.");
                response = sb.ToString();
                /*
                sb.Append("<table style='width:100%;'><tr><td style='width:180px;'>");
                sb.Append(rdr["pro"].ToString() + "</td><td style='width:20%;'>");
                sb.Append(rdr["sn"].ToString() + "</td><td style='width:10%;'>");
                sb.Append(rdr["po"].ToString() + "</td><td style='width:20%;' align='center'>");
                sb.Append(rdr["qty"].ToString() + "</td><td style='width:10%;' align='center'>");
                sb.Append(rdr["status"].ToString() + "</td><td style='width:20%;' align='center'>");
                sb.Append("<input type='image' src='images/temporaryStar.png' /></td></tr></table><div><p></p></div>");
                response = sb.ToString();*/
            }
          }
        }
      }
    }
    return response;
  }
}

我听说过 IE 粗鲁的兼容性惊喜,但我不认为这里是这种情况。

编辑:嗯,我找到了一些东西,但我不知道该怎么做。

'iexplore.exe' (Script): Loaded 'Script Code (Windows Internet Explorer)'. 
Exception was thrown at line 4, column 13743 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 13957 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 10598 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 4, column 4377 in http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
0x800a03f6 - JavaScript runtime error: Invalid character

【问题讨论】:

  • 尝试在使用 IE 的同时运行 Fiddler 以查看失败的确切位置。
  • 500 内部服务器错误通常意味着服务器端代码中抛出了异常。我不禁注意到您没有在代码中捕获或记录异常。也许您忽略了一个信息错误?
  • 您是否尝试过附加到 ASP.NET 进程?您可以将调试器附加到 w3wp.exe(调试 > 附加到进程...),并打开捕获抛出的异常。
  • 在代码中加入try catch,然后调试。写入异常并更新您的帖子。
  • 如果您使用 Visual Studio 进行调试,请按ctrl + alt + e 调出Exceptions dialogue。然后检查Common Language Runtime Exceptions 下的thrown。这将停止大多数隐藏的错误。

标签: c# asp.net visual-studio internal-server-error


【解决方案1】:

您应该在 &lt;system.web&gt;-node 内的 web.config 中添加以下内容:

<customErrors mode="On|Off|RemoteOnly">

要显示详细的错误信息,请将mode 的值设置为Off

【讨论】:

  • 我相信我之前已经尝试过了。再试一次,我看不出有什么不同。
  • 基本上,您在浏览器中更改的内容并不重要,服务器只是向您发送带有非描述性 HTML 的 500。如果您想要完整的堆栈跟踪,您可以通过更改我的答案中的 customerrors 来实现。如果你有这个,但仍然不知道是什么原因,你应该在代码中放置一个断点并单步执行它,看看哪里出错了。
猜你喜欢
  • 2011-05-17
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 2019-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多