【问题标题】:An unhandled exception occurred during the execution of the current web request. ASP.NET当前 Web 请求执行期间发生未处理的异常。 ASP.NET
【发布时间】:2020-09-18 14:19:33
【问题描述】:

我刚刚运行了我的程序并收到了这个错误消息

当前执行过程中发生了未处理的异常 网络请求。请查看堆栈跟踪以获取有关的更多信息 错误及其源自代码的位置。

带有堆栈跟踪

[NullReferenceException: Object reference not set to an instance of an object.]
   OverseasCreditCard.Default.Page_Load(Object sender, EventArgs e) +667
   System.Web.UI.Control.LoadRecursive() +70
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177

我正在使用 ASP.NET C#,有人知道发生了什么吗?

【问题讨论】:

标签: c# asp.net


【解决方案1】:

信息不完整:我们需要知道哪一行抛出 NullReferenceException 以便准确判断问题出在哪里。

显然,您正在使用未初始化的变量(即,已声明但未初始化的变量)并尝试访问其非静态方法/属性/其他之一。

解决方案: - 从异常详细信息中找到引发异常的行 - 在这一行中,检查您使用的每个变量是否已正确初始化(即它不为空)

祝你好运。

【讨论】:

  • 这不是答案。这是一个信息请求,充其量只是一些解决错误的指南。
【解决方案2】:

我遇到了同样的问题,发现我忘记将脚本包含在要包含在实时站点中的文件中。

另外,你应该试试这个:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));

【讨论】:

    【解决方案3】:

    这是第156行的代码,上面有try and catch

        /// <summary>
        /// Execute a SQL Query statement, using the default SQL connection for the application
        /// </summary>
        /// <param name="query">SQL query to execute</param>
        /// <returns>DataTable of results</returns>
        public static DataTable Query(string query)
        {
            DataTable results = new DataTable();
            string configConnectionString = "ApplicationServices";
    
            System.Configuration.Configuration WebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/Web.config");
            System.Configuration.ConnectionStringSettings connString;
    
            if (WebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
            {
                connString = WebConfig.ConnectionStrings.ConnectionStrings[configConnectionString];
    
                if (connString != null)
                {
                    try
                    {
                        using (SqlConnection conn = new SqlConnection(connString.ToString()))
                        using (SqlCommand cmd = new SqlCommand(query, conn))
                        using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd))
                            dataAdapter.Fill(results);
    
                        return results;
                    }
                    catch (Exception ex)
                    {
                        throw new SqlException(string.Format("SqlException occurred during query execution: ", ex));
                    }
                }
                else
                {
                    throw new SqlException(string.Format("Connection string for " + configConnectionString + "is null."));
                }
            }
            else
            {
                throw new SqlException(string.Format("No connection strings found in Web.config file."));
            }
        }
    

    【讨论】:

      【解决方案4】:
      1. 如果您遇到此问题(输入 windows + R)删除 temp(%temp%) 和 windows temp。
      2. 此时停止 IIS(Internet 信息服务)并删除所有剩余文件。

      检查您的问题是否已解决。

      【讨论】:

        猜你喜欢
        • 2014-04-21
        • 2016-04-25
        • 1970-01-01
        • 1970-01-01
        • 2020-06-09
        • 1970-01-01
        • 1970-01-01
        • 2022-01-17
        • 2015-12-14
        相关资源
        最近更新 更多