views:

110

answers:

2

I've just converted a project from MVC1 to MVC2. In the MVC1 project the HTTP status code was being set in some of the views. These views are now generating this exception:

Server cannot set status after HTTP headers have been sent.

What has changed from MVC1 to MVC2 to cause this and is there any way to fix this?

A: 

You might want to check this thread on this exact issue:

http://stackoverflow.com/questions/2383169/server-cannot-set-status-after-http-headers-have-been-sent-iis7-5

Kelsey
@guy if this answer helped you don't forget to mark it as the accepted answer. If you are still experiencing this problem update your question and I will see if I can figure it out.
Kelsey
+1  A: 

I would argue that you shouldn't be setting any status codes in the views at all. Is this not the role of the controller at most?

Matthew Abbott
Generally I would agree with you but this was a case where I was using the view from multiple locations in the Controllers and wanted to apply the DRY principal so I only wanted to set the Status Codes in one location.
Guy