EventSource をコントローラーに接続しようとすると、次のように言い続けます。
EventSource の応答に、「text/event-stream」ではない MIME タイプ (「text/html」) があります。接続を中止しています。
応答の処理と準備を支援するために、次のクラスを作成しました。このクラスでは、それに応じて responseType を設定したと思いtext/event-stream
ます。
public class ServerSentEventResult : ActionResult
{
public delegate string GetContent();
public GetContent Content { get; set; }
public int Version { get; set; }
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (this.Content != null)
{
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = "text/event-stream"; response.BufferOutput = false; response.Charset = null;
string[] newStrings = context.HttpContext.Request.Headers.GetValues("Last-Event-ID");
if (newStrings == null || newStrings[0] != this.Version.ToString())
{
try
{
response.Write("retry:250\n");
response.Write(string.Format("id:{0}\n", this.Version));
response.Write(string.Format("data:{0}\n\n", this.Content()));
response.End();
}
catch (HttpException e) { }
}
else
{
response.Write(String.Empty);
}
}
}
}
誰かがこれについて私を助けてくれませんか?何千回もよろしくお願いします!