读书人

Global.asax的Application_Start中不能

发布时间: 2011-12-14 23:20:17 作者: rapoo

Global.asax的Application_Start中不能用Transfer执行指定页面吗?
private void Application_Start(object sender, EventArgs e)
{
HttpContext ctx = HttpContext.Current;
//ctx.Server.Execute( "Error.aspx ");
ctx.Server.Transfer( "Error.aspx ");
}
以前代码无论用Execute还是Transfer执行另外的一个aspx页面,都出现异常。

[NullReferenceException: 未将对象引用设置到对象的实例。]
System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +416

[HttpException (0x80004005): 为 Error.aspx 执行子请求时出错。]
System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +719
System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm) +53
System.Web.HttpServerUtility.Transfer(String path) +27

这是怎么回事呢?难道在Application_Start不能用Transfer吗?有办法解决吗?谢谢!

[解决办法]

HttpContext ctx = HttpContext.Current;
//ctx.Server.Execute( "Error.aspx ");
ctx.Response.Redirect( "http://dotnet.aspx.cc ");

读书人网 >asp.net

热点推荐