When I try to hook my controller to EventSource, it keeps saying:
EventSource Response contains a MIME type ("text / html") that is not "text / event-stream" canceling connection.
I have created the following class to help in handling a handle and preparing the reaction. In this class I believe that I set the
text / event-stream according to the response.
public class ServerSentEventResult: ActionResult {public representative string GetContent (); Public GetContent Content {get; Set; } Public int version {get; Set; } Public Override Zero ExecuteResult (Controller Context Reference) {if (context == null) {New argument NullException ("Reference"); } If (this. Content! = Null) {HTPRPPointbase response = reference. Hpptntx response; reaction. Contact type = "text / event-stream"; reaction. BufferOutput = false; reaction. Chargset = Faucet; String [] newStrings = context.HttpContext.Request.Headers.GetValues ("last-event-id"); If (new prohibited == faucet || New Saltings [0]! = This.Vision.Testring ()) {Try {feedback. Type ("retry: 250 \ n"); reaction. Type (string format ("id: {0} \ n", this version)); reaction. Type (string.Format ("Data: {0} \ n \ n", this. Content ())); Response.End (); } Hold (HttpException E) {}} and {response.Write (String.Empty); }}}}
Can someone help me on this? Thank you thousands of times in advance!
Sorry for the late reply.
Do I have to prepare my entire response in a string builder in my code and then write it down and flush it at once (do not write 3 at the end)
Var sb = new StringBuilder (); Sb.Append ("Try again: 1 \ n"); Sb.AppendFormat ("id: {0} \ n", this version); Sb.AppendFormat ("id: {0} \ n \ n", this. Content ()); Response.ContentType = "text / event-stream"; Response.Write (sb.ToString ()); Response.Flush ();
On another note, my code is in an MVC controller, so I'm not responding to myself (I use it. Response) which means that only in my header Contains more data than ContentType.
Comments
Post a Comment