tpeczek/Lib.AspNetCore.ServerSentEvents

Routing Problem when published on IIS Application.

axanth opened this issue · 8 comments

When the application is published as IIS Application i get error 500 ( https://localhost:4433/sse-notifications ). I guess this is because the /appname/ does not get added to the path so routing fails.
Tried to put the app name in the path in call to :
endpoints.MapServerSentEvents("/RCB/sse-notifications"); but has no effect.. any help?

Can you provide the body of that 500 (or anything you can find in logs) and your pipeline configuration?

Never-mind. I fell into a trap. It was a combination of 2 issues so it kinda confused me! One had to do with app poll in IIS (solved). The other solved it by adding ~ to the Path in endpoints.MapServerSentEvents("~/sse-notifications").

Thank you for having the time to respond!! Keep well!!

Sorry my mistake the error now is 404 .... not found

Request URL: https://localhost:4433/sse-notifications
Request Method: GET
Status Code: 404
Remote Address: [::1]:4433
Referrer Policy: no-referrer-when-downgrade

the problem has to do with routing ... the path of get is https://localhost:4433/sse-notifications but
the application is published as IIS Application and it should be https://localhost:4433/**RCB**/sse-notifications

When the application is published as IIS Site (no application) it works fine!

services.AddServerSentEvents();
        services.AddServerSentEvents<INotificationsServerSentEventsService, NotificationsServerSentEventsService>();
        services.AddTransient<INotificationsService, LocalNotificationsService>();

        services.AddResponseCompression(options =>
        {
            options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "text/event-stream" });
        });

app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapServerSentEvents("~/sse-notifications");
});

I'm a little bit confused now. The URL to which the request is made (in your case https://localhost:4433/sse-notifications) it's not a result of routing configuration.

What you configure in Startup.cs is the endpoint on which this library will listen for SSE, this library doesn't generate the URL to be used from frontend.

If you have been copying from the demo application, this URL is probably hardcoded somewhere, or it is being incorrectly generated by one of ASP.NET Core helpers.

You are right! The problem was in JavaScript and in the line:
var source = new EventSource('../sse-notifications'); it was missing the .. for the relative path !! Sorry for the trouble! Thank you for your time!!