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 ");