试图处理这个问题,但不明白为什么会出现这样的错误。
我在 cosole Google Chrome 中收到此错误:EventSource 的响应具有不是“text/event-stream”的 MIME 类型(“text/html”)。中止连接。
public class Item {
public int Index { get; set; }
public int Value { get; set; }
}
public class DataRetModel {
public List<Item> Items { get; set; }
public Item Item { get; set; }
}
ServerEvents.NotifySession(user.SessionId, new DataRetModel{...init...});
感谢帮助!
…………
在使用 Fidler 分析请求后(感谢@mythz 的想法),我发现以下内容:如果您在一个浏览器中注销,则有 2 个客户端浏览器运行服务器事件的处理程序,那么另一个浏览器将获得 2 个事件,一个正常,另一个“EventSource 的响应具有 MIME 类型”(http 状态 = 401)。
现在问题出现了,如果我向他们发送 SessionId,为什么两个客户端都会收到所有事件?
您可以让每个用户都收到他们的事件吗?
var eventSource = new EventSource('/event-stream');
客户端处理程序:
$(eventSource).handleServerEvents({
handlers: {
DataRetModel: function (data) {
console.log(data);
}
}
});