Signalr 信号器自主机和静态文件服务器(例如owin.selfhost)

Signalr 信号器自主机和静态文件服务器(例如owin.selfhost),signalr,owin,Signalr,Owin,我已经“太”成功地使用了我的独立单一web服务。我们现在想删除IIS服务器,它只提供大约10个JS/HTML/CSS文件。Node.JS有一个静态文件插件 我看了看,我发现Katana,OWIN.SelfHost也有这样一个功能。 更新 有人建议使用OWIN.Self-Host,它有一个特性,但我不确定将它放在我现有的代码中的什么位置,以及它是否会影响现有的信号器代码(所有集线器共享相同的HTTP请求调用,因此我也在同一端口上压缩Self-Host,我不知道这是否有效)。使用Scott Al

我已经“太”成功地使用了我的独立单一web服务。我们现在想删除IIS服务器,它只提供大约10个JS/HTML/CSS文件。Node.JS有一个静态文件插件

我看了看,我发现Katana,OWIN.SelfHost也有这样一个功能。


更新

有人建议使用OWIN.Self-Host,它有一个特性,但我不确定将它放在我现有的代码中的什么位置,以及它是否会影响现有的信号器代码(所有集线器共享相同的HTTP请求调用,因此我也在同一端口上压缩Self-Host,我不知道这是否有效)。使用Scott Allen的()示例也很好,该示例还允许文件浏览

以下是我当前用于启动SIGNALR(V2.2)的代码,它直接从Main.cs文件运行:

class Comm
{
    public string url = "http://localhost:7700";
    // string url = "http://*:7700"; // Requires admin privileges
    public void start()
    {
        Task t = Task.Run(() =>
        {
            WebApp.Start<Startup>(url);
            this.Clients = GlobalHost.ConnectionManager.GetHubContext<GatewayHub>().Clients;
            Console.WriteLine("Server running on {0}", url);
            Thread.Sleep(Timeout.Infinite);
        });
    }
    public void send()
    {
        Clients.All.display("broadcast sent...");
    }
    private IHubConnectionContext<dynamic> Clients
    {
        get;
        set;
    }
}
class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var hubConfiguration = new HubConfiguration();
        hubConfiguration.EnableDetailedErrors = (Tools.LogLevel >= 12);
        hubConfiguration.EnableJavaScriptProxies = true;
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR("/signalr", hubConfiguration);
    }
}
类通信
{
公共字符串url=”http://localhost:7700";
//string url=“http://*:7700”//需要管理员权限
公开作废开始()
{
Task t=Task.Run(()=>
{
WebApp.Start(url);
this.Clients=GlobalHost.ConnectionManager.GetHubContext().Clients;
WriteLine(“在{0}上运行的服务器”,url);
Thread.Sleep(Timeout.Infinite);
});
}
公共无效发送()
{
Clients.All.display(“广播已发送…”);
}
专用IHubConnectionContext客户端
{
得到;
设置
}
}
类启动
{
公共无效配置(IAppBuilder应用程序)
{
var hubConfiguration=新的hubConfiguration();
hubConfiguration.EnableDetailedErrors=(Tools.LogLevel>=12);
hubConfiguration.EnableJavaScriptProxies=true;
应用程序UseCors(CorsOptions.AllowAll);
app.MapSignalR(“/signalr”,HUB配置);
}
}

这个答案确实来自@tracher,我希望他能写出来,这样我就可以相信他了。但多亏了他的投入,这才是适合我的。我不需要注释的行。我所需要的只是为/signlar和静态文件系统设置路径

}
class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var hubConfiguration = new HubConfiguration();
        hubConfiguration.EnableDetailedErrors = (Tools.DebugLevel > 12);
        hubConfiguration.EnableJavaScriptProxies = true;
        app.UseCors(CorsOptions.AllowAll);
        //app.UseStaticFiles();
        app.UseFileServer(new FileServerOptions()
        {
            //RequestPath = new PathString("/Scopes"),
            EnableDirectoryBrowsing = true,
            FileSystem = new PhysicalFileSystem(@".\Scopes"),
        });
        app.MapSignalR("/signalr", hubConfiguration);
    }
}

app.UseStaticFiles();思维敏捷@Tratcher(德语内部笑话)。我更新了我的问题,提出了我对ading app的担忧。UseStaticFiles()静态文件不应该干扰SignalR,因为如果它找不到给定的请求路径,它将传递到下一个组件。目录浏览可能会导致更多问题,因为它有更短的路径来匹配,并且更可能发生冲突。Signal试图通过将
/Signal
添加到其路径来避免这种情况,因此只要您没有名为Signal的目录,您就可以了。添加目录浏览会干扰Singular,因为打开请求返回的是目录,而不是Singular服务器。如果你有一个解决方案,只浏览一个子目录或一个不同于可执行文件的文件夹,并把它写下来作为一个答案,我会给你这个问题的信用。