Reputation: 5691
I want to host a Self-Host SignalR process locally on port 80 and having a local http directory hosted on the same port (serving files from a certain directory, mapping the directory structure to HTTP requests).
For example accessing localhost:80/index.html
will return a html file located in a certain directory,
that also communicates with the SignalR process on the same port, because having different ports will cause an error in chrome browser due to same origin policy.
Any idea how can I achieve it? since I cannot bind the same port with two different applications.
Upvotes: 1
Views: 3665
Reputation: 18402
As long as we're talking about SignalR 2.x and you can serve your other content via WebAPI, this is possible since they both use OWIN. With MVC, things are more complicated.
To run SignalR and WebAPI on the same port, you'd have to install Microsoft.AspNet.WebApi.OwinSelfHost
in your SignalR applilcation and modify the Owin.IAppBuilder to use Web API:
public static class Startup
{
public static void Configuration(IAppBuilder app)
{
var httpConfig = new HttpConfiguration();
httpConfig.Routes.MapHttpRoute("Default", "api/{controller}/{id}",
new {id = RouteParameter.Optional});
app.UseWebApi(httpConfig);
app.MapSignalR();
}
}
Note that you could also use CORS to get around that browser issue.
Upvotes: 3