c# - 我的 Visual Studio 2008 Web 应用程序在首次运行时不断抛出 .Net 错误,但刷新后可以解决该问题

标签 c# .net asp.net

如标题所述,我的 Web 应用程序构建成功,尽管每次我在 Debug模式下运行它时都会收到以下 .Net 错误:

img

如果我点击刷新,那么应用程序不会再出现错误,直到我下次再次启动它为止,有什么想法吗?

这是我的 global.asax 文件:

<%@ Application Language="C#" Inherits="MyCompany.Web.MyApp.Shell.CustomWebClientApplication" %>

<script runat="server">

    void Session_End(Object Sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
    }

    protected void Session_Start(Object sender, EventArgs e)
    {
        if (Session.IsNewSession)
        {
            Response.Redirect(System.Web.Configuration.WebConfigurationManager.AppSettings["HomePage"]);
        }
    }

    protected void Application_Error(Object sender, EventArgs e)
    {
        System.Exception oops = Server.GetLastError();

        //Injection attack error handling
        if (oops.GetBaseException() is System.Web.HttpRequestValidationException)
        {
            Response.Redirect("ErrorPage.aspx");
        }
    }

</script>

最佳答案

您有一些东西正在尝试访问设置为 null(或尚未初始化)的变量。 Global.asax 中是否有任何内容或在应用程序启动时触发的内容?您是否有在应用程序启动时触发的异步操作?

检查您的 Home.aspx 页面,看看那里发生了什么。看起来您的应用程序重定向到该页面,因此我猜测在 init 或 page_load 事件中正在执行的某些内容导致了问题。

关于c# - 我的 Visual Studio 2008 Web 应用程序在首次运行时不断抛出 .Net 错误,但刷新后可以解决该问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2638163/

相关文章:

javascript - 如何将变量作为字符串参数放入google的API data.addRows ('string' ,值)

c# - iOS webapp 启动画面缓存

c# - 覆盖 DateTime.MinValue 导致问题

c# - 如何切换 .NET 程序集以执行一种方法?

c# - LINQ 查询中的 "=>"标志是什么?

使用空的已发布文件集合上传 ASP.Net 文件

c# - C#中如何获取字符串的内存地址?

c# - 你如何在同一时刻启动 2 个线程?

c# - EF核心: how to model a relationship attribute?

.net - 将依赖项合并到控制台应用程序中