Who*_*mmy 9 asp.net asp.net-mvc
我听说过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)
{
}
Run Code Online (Sandbox Code Playgroud)
我可以通过创建默认的ASP.NET MVC应用程序并添加上面的代码来重现该问题.奇怪的是这个代码在我的旧主机上运行良好,它只在我的新(共享)主机上崩溃.如果我的代码中有这些事件处理程序,我会收到此错误:
'/'应用程序中的服务器错误.你调用的对象是空的.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例.
源错误:在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
堆栈跟踪:
[NullReferenceException:对象引用未设置为对象的实例.] System.Web.PipelineModuleStepContainer.GetStepArray(RequestNotification notification,Boolean isPostEvent)+27 System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification,Boolean isPostEvent)+11 System.Web .PipelineStepManager.ResumeSteps(异常错误)+205 System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context,AsyncCallback cb)+91 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)+514
我尝试使用Softsys对此进行故障排除,但它们不是很有用,基本上它们只是确认我在管理控制面板中打开了"ASP.NET管道(MVC)"功能.
有人可以:
zih*_*tki 16
您需要在每个HttpApplication实例中注册处理程序.可能有几个HttpApplication池化实例.Application_Start仅被调用一次(对于经典模式下的IIS 6和IIS 7 - 在第一次请求时,对于IIS 7集成模式 - 在Web应用程序启动时,就在任何请求之前).因此,要使所有工作正常,您需要在HttpApplication的重写Init方法或其构造函数中添加事件处理程序.如果在构造函数中添加它们 - 这些处理程序将首先被调用,甚至在注册模块的处理程序之前.
所以你的代码应该是这样的:
public class MySmartApp: HttpApplication{
public override void Init(){
this.BeginRequest += new EventHandler(MvcApplication_BeginRequest);
this.EndRequest += new EventHandler(MvcApplication_EndRequest);
}
protected void Application_Start(){
RegisterRoutes(RouteTable.Routes);
}
}
Run Code Online (Sandbox Code Playgroud)
或者像这样:
public class MySmartApp: HttpApplication{
public MySmartApp(){
this.BeginRequest += new EventHandler(MvcApplication_BeginRequest);
this.EndRequest += new EventHandler(MvcApplication_EndRequest);
}
protected void Application_Start(){
RegisterRoutes(RouteTable.Routes);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4135 次 |
| 最近记录: |