如标题所述,我的 Web 应用程序构建成功,尽管每次我在 Debug模式下运行它时都会收到以下 .Net 错误:
如果我点击刷新,那么应用程序不会再出现错误,直到我下次再次启动它为止,有什么想法吗?
这是我的 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/