我在思考一个问题,这几天一直困扰着我:是否可以在IIS中托管SignalR Hub?这种情况是否可能发生?我找到了一个名为“自托管”的解决方案,但需要借助控制台应用程序。我想在我的IIS中托管SignalR Hub,这是否可能?有人能提供相关示例吗?
我将发布自托管代码,希望能够帮到大家。
class Program
{
static void Main(string[] args)
{
// This will *ONLY* bind to localhost, if you want to bind to all addresses
// use http://*:8080 to bind to all addresses.
// See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
// for more information.
string url = "http://localhost:8080";
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
public class MyHub : Hub
{
public void Send(string name, string message)
{
Clients.All.addMessage(name, message);
}
}