4

I have a application that make warning in IIS.

When I tried it in my visual studio, nothing in error. I made a Application_Error in the global.asax to catch unhanded exceptions.

Here are informations 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 the user land to the webapplication, if there is no session, he is redirected to a auth service that redirect too the user in the webapplication, with a token in URL to authenticater the user.

This is during this process that the error is thrown.

EDIT: maybe it's this code that generate 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);
}
James
  • 2,195
  • 1
  • 19
  • 22
clement
  • 4,204
  • 10
  • 65
  • 133
  • 2
    Please post the acutal code raising the error. – Alexander Jan 10 '14 at 12:28
  • http://stackoverflow.com/questions/2383169/server-cannot-set-status-after-http-headers-have-been-sent-iis7-5?rq=1 – Tsasken Jan 10 '14 at 13:19
  • Usually this is caused by manually calling HttpContext.Current.Response.End() or HttpContext.Current.Response.Redirect() before return in action. Try put your redirect into a return Redirect() in an action – tweray Jan 10 '14 at 13:19
  • @Alexander : Ok thanks, I've added the code segment I expect generate the error! – clement Jan 10 '14 at 14:12
  • @WeTTTT : OK thanks, but this is not possible because of the definition of the method (void OnActionExecuting(...)) – clement Jan 10 '14 at 14:55
  • Is the ConfigManager.AuthService in your code pointing to an action? If so can you try replace it with RedirectToAction() and see if the exception still getting thrown? – tweray Jan 10 '14 at 15:48
  • @WeTTTT : No, this is a external URL like https://auth.domain.com. the auth will authenticate the user and redirect it to https://myWebAppThatCausesWarning.com/authenticationToken – clement Jan 14 '14 at 09:03

1 Answers1

1

The action method is still being triggered even when you call Response.Redirect and RedirectToAction.

To fix it, change the redirect lines to

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

and

filterContext.Result = Redirect(ConfigManager.AuthService);
LostInComputer
  • 15,188
  • 4
  • 41
  • 49
  • ok thanks it looks that it resolved part of my problem. There still errors but I made a big IF clause to redirect the application directly! Thanks! – clement Jan 13 '14 at 11:08