I've created a self hosting Owin/SignalR app with code similar to the code in this tutorial:
Everything works, but for security-sake, I'd like to limit it to only allow messages from a specific remote site. In other words, I'd like to replace the "app.UseCors(CorsOptions.AllowAll);" line with code to confine the app to only responding to messages from a URL that I define, i.e. only allow messages from, say, http://www.remote_site.com or something. Is there any easy way to do this?
For reference, here is the code for my SignalR startup class:
using System;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Owin;
using Microsoft.Owin.Cors;
namespace SignalRSelfHost
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
// How do I only allow a specific URL instead of the "CorsOptions.AllowAll" option?
}
}
}
Here's the code that I mentioned in a comment above:
This works, but I think Matei's answer above is cleaner and simpler.
Here is the full implementation of the
Owin Startup
class:Also, if you want to server to accept a list of domains, you simply add them to the
Origins
.Hope this helps! Good luck!