我听说Softsys Hosting非常好,所以我决定将我的ASP.NET MVC解决方案迁移到他们的平台上。但是它无法在他们的平台上运行。我能够确定问题出在我的BeginRequest事件处理程序上。如果我有这些处理程序,就会出现错误。以下是我的代码:
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
this.BeginRequest += new EventHandler(MvcApplication_BeginRequest);
this.EndRequest += new EventHandler(MvcApplication_EndRequest);
}
void MvcApplication_EndRequest(object sender, EventArgs e)
{
}
void MvcApplication_BeginRequest(object sender, EventArgs e)
{
}
我可以通过创建默认的ASP.NET MVC应用程序并添加上述代码来重现此问题。奇怪的是,这段代码在我的旧主机上运行良好,但只会在我的新(共享)主机上崩溃。如果我在代码中有这些事件处理程序,我就会得到以下错误:
服务器错误在'/'应用程序。
对象引用未设置为对象实例。说明:在当前网络请求执行期间发生未处理的异常。请查看堆栈跟踪以获取有关错误的更多信息以及错误在代码中的源和位置的信息。
异常详细信息:System.NullReferenceException: 对象引用未设置为对象实例。
源错误:在当前网络请求执行期间生成了一个未处理的异常。可以使用下面的异常堆栈跟踪标识异常的起源和位置。
堆栈跟踪:
[NullReferenceException: 对象引用未设置为对象实例。] System.Web.PipelineModuleStepContainer.GetStepArray(RequestNotification notification, Boolean isPostEvent) +27 System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification, Boolean isPostEvent) +11 System.Web.PipelineStepManager.ResumeSteps(Exception error) +205 System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +91 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +514
我尝试与Softsys进行故障排除,但他们没有提供太多帮助,基本上只确认我已经在我的管理员控制面板中打开了“ASP.NET Pipeline (MVC)”功能。
有人能:
1.告诉我是否编写了错误的代码 2.向我展示解决方法 3.解释为什么在一个主机上出现此错误而在另一个主机上没有。