C# 试图将Global.asax 1.0文件转换为3.5版本,出现应用程序错误+会话和重定向问题

C# 试图将Global.asax 1.0文件转换为3.5版本,出现应用程序错误+会话和重定向问题,c#,asp.net-3.5,session-variables,global-asax,C#,Asp.net 3.5,Session Variables,Global Asax,因此,在Global.asax中: 受保护的无效应用程序\u Errorobject发送者,System.EventArgs { 会话[CustomError]=Server.GetLastError; Server.ClearError; Response.Redirect~/ErrorPage.aspx; } 在ErrorPage.aspx中是这样的: 私有无效页\加载对象发送方,System.EventArgs e { Exception currentException=Exceptio

因此,在Global.asax中:

受保护的无效应用程序\u Errorobject发送者,System.EventArgs { 会话[CustomError]=Server.GetLastError; Server.ClearError; Response.Redirect~/ErrorPage.aspx; }

在ErrorPage.aspx中是这样的:

私有无效页\加载对象发送方,System.EventArgs e { Exception currentException=ExceptionSession[CustomError]。InnerException

//写入错误消息 如果currentException!=null txtErrorMessage.Text=currentException.Message

//循环遍历内部异常。 currentException=ExceptionSession[CustomError]; 而currentException!=null { message.AppendcurrentException.message.Append\r\n.AppendcurrentException.StackTrace; message.Append\n====================================================================================================\n; currentException=currentException.InnerException; }

由于这是旧的1.0代码,当转换为3.5 Global.asax文件时会呕吐。它告诉我会话不可用,并且我无法重定向??我认为问题之一可能是应用程序启动时也会抛出一个错误。但是如果我注释掉所有应用程序启动代码,我仍然会得到错误,但它们永远不会得到重定向请转到错误页。

此链接可能有帮助:。 此外,使用web.config文件定义错误的默认重定向页面