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

时间:2015-12-22 15:28:41

标签: signalr owin

我一直都是""成功使用我的独立Singular Web服务。我们现在想要删除IIS服务器,除了提供大约10个JS / HTML / CSS文件之外,它几乎没有。 Node.JS有一个静态文件插件,

我看了,我看到Katana,OWIN.SelfHost也有这样的功能。 http://odetocode.com/blogs/scott/archive/2014/02/10/building-a-simple-file-server-with-owin-and-katana.aspx

更新

建议使用具有功能的OWIN.Self-Host,但我不确定将其放在现有代码中的位置,以及是否会影响现有的SIGNALR代码(所有集线器共享相同的HTTP请求)电话,所以我也在同一个端口挤压自主机,我不知道是否有效)。除了使用Scott Allen(above referenced)示例(也允许文件浏览)之外,这将是一件好事。

这是我当前用来启动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);
    }
}

1 个答案:

答案 0 :(得分:2)

这个回答真的来自@Tracther,我希望他能写出来,以便我可以信任他。但是由于他的意见,这对我有用。我不需要注释行。我只需要为/ signlar和静态FileSystem设置路径

}
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);
    }
}
相关问题