I can't allow unhandeld exception: cannot set status after HTTP headers are already set

I have an application that makes a warning in IIS.

When I tried this in my own way visual studio, nothing happened. I did Application_Errorin global.asaxto catch unhanded exceptions.

Here is the information about this error:

Message: Server cannot set status after HTTP headers have been sent.
Source: System.Web. 
InnerException:  (none)
End of stacktrace:

   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

How can I debug it?

When a user lands on a web application, if not session, he is redirectedfor the auth service, which is redirectalso a user in the web application, with a token in the URL for user authentication.

An error occurs during this process.

EDIT: maybe this code generates a warning

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    string token = Request.QueryString["token"];
    // In the case I suspect to generate warning, the token is null!
    if (!string.IsNullOrEmpty(token))
    {
        SessionManager.IdentityToken = token;
        SessionManager.UserDatas.IdentityToken = token;
        SSOInformations sso = SSOManager.GetSSO(new Guid(token), false);
        if (sso != null)
        {
            SessionManager.UserDatas.loginID = sso.login;

            // Get and set session
            // Code

            catch (Exception ex)
            {
                TempData["ERROR_MESSAGE"] = ex.Message;
                RedirectToAction("index", "error");
            }
        }
        else
        { // if the sso failed, retry to authenticate
             Response.Redirect(ConfigManager.AuthService);
          // 31122013 : CHA : to avoid to write warnings on the server
              return;
        }
        //}
    }

    base.OnActionExecuting(filterContext);
}
+4
1

, Response.Redirect RedirectToAction.

,

filterContext.Result = RedirectToAction("index", "error");

filterContext.Result = Redirect(ConfigManager.AuthService);
+1

All Articles