I've got an MVC Site that is giving an "Server cannot modify cookies after HTTP headers have been sent." error. It's happening in the _Layout.cshtml. At that line, there is a @Html.Action("_LightBoxes"), which calls a _LightBoxes partial view. The code for the _LightBoxes Partial View is simply:-
[ChildActionOnly]
public PartialViewResult _LightBoxes()
{
return PartialView();
}
I've read other threads with this error, but these all seem to be performing re-directs or similar, where as in this controller it simply returns an empty Partial View.
Does anyone have any suggestions for what is causing this? Could it be a reference inside that PartialView to another controller which is actually causing this error?
EDIT - 26 JANUARY 2015 I think this might be the issue. This is in a Partial View called from within the PartialView at that line. Code below, for a Facebook login button, which has cookies set to true.
<script type="text/javascript">
//Facebook Login Button
window.fbAsyncInit = function () {
FB.init({
appId: "@(System.Configuration.ConfigurationManager.AppSettings["facebook_appid"].ToString())", // App ID
//channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status: true, // check login status
cookie: false, // enable cookies to allow the server to access the session
oauth: true, // enable OAuth 2.0
xfbml: true // parse XFBML
});
$("fblogin").show();
};
(function (d) {
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
//End Facebook
</script>
Thanks, Mike.