开发者

Error handling in global.asax MVC 3.0 problem on server 2008

I created

protected void Application_Error(object sender, EventArgs e)
{
   if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)
   {
      try
      {
         var httpContext = HttpContext.Current;
         Exception exception = httpContext.Server.GetLastError();

         if (exception is HttpRequestValidationException)
         {
            httpContext.Response.Clear();
            var logLoggerService = new LogLoggerService();
            l开发者_如何学PythonogLoggerService.Error("ValidationException", exception);
            WriteErrorResponse(exception.Message);
         }
         else
         {
            httpContext.Response.Clear();
            var logLoggerService = new LogLoggerService();

            logLoggerService.Error(exception);
            WriteErrorResponse(exception.Message);
         }
     }
     catch
     {
        var httpContext = HttpContext.Current;
        httpContext.Response.Clear();
     }
  }
}

I found that when error occurred on server, this function is not call. But when I am in debug mode, the Application_Error is called.

Why this does not work on server? Maybe problem with IIS or with .NET 4.0 on server?

On server I have:

Event code: 3005 Event message: An unhandled exception has occurred. Event time: 15-8-2011 8:25:26 Event time (UTC): 15-8-2011 6:25:26 Event ID: ae3cad590adc43c3803410023cccb6b0 Event sequence: 4 Event occurrence: 1 Event detail code: 0

Application information: Application domain: /LM/W3SVC/11/ROOT-1-129578631124796958 Trust level: Full Application Virtual Path: / Application Path: C:\inetpub\wwwroot\TestnaAplikacijaZaLog\ Machine name: SRJ1-SRV-01

Process information: Process ID: 6644 Process name: w3wp.exe Account name: IIS APPPOOL\TestnaAplikacijaZaLog

Exception information: Exception type: HttpException Exception message: Response is not available in this context. at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

Response is not available in this context. at System.Web.HttpContext.get_Response() at LogiranjeGresaka.MvcApplication.Application_Start() in c:\users\esmira\documents\visual studio 2010\Projects\LogiranjeGresaka\LogiranjeGresaka\Global.asax.cs:line 46

Request information: Request URL: http://192.168.0.100:2227/Home/Index Request path: /Home/Index User host address: 192.168.0.103 User:

Is authenticated: False Authentication Type:

Thread account name: IIS APPPOOL\TestnaAplikacijaZaLog

Thread information: Thread ID: 7 Thread account name: IIS APPPOOL\TestnaAplikacijaZaLog Is impersonating: False Stack trace: at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

Custom event details:


I solve problem with adding

<system.web>
  <customErrors mode="Off" />
</system.web>


This is being called, but the error is being thrown by the code above as detailed by the error message:

Exception information: Exception type: HttpException Exception message: Response is not available in this context

You are trying to use Response, but you can't.


Right here, it is telling you the line number where the problem is:

Response is not available in this context. at System.Web.HttpContext.get_Response() at LogiranjeGresaka.MvcApplication.Application_Start() in c:\users\esmira\documents\visual studio 2010\Projects\LogiranjeGresaka\LogiranjeGresaka\Global.asax.cs:line 46

Line 46 Global.asax

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜