c# – SignalR with vNext

前端之家收集整理的这篇文章主要介绍了c# – SignalR with vNext前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我很难在vNext项目中使用SignalR(epmty模板).

Firsty我将SignalR.Server依赖项添加到我的project.json文件中,它现在看起来像这样:

{
    "webroot": ".","dependencies": {
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta3","Microsoft.AspNet.Server.WebListener": "1.0.0-*","Microsoft.AspNet.StaticFiles": "1.0.0-*","Microsoft.AspNet.SignalR.Server": "3.0.0-*","Serilog": "1.4.113.0"
},"commands": {
        "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5002"
    },"frameworks": {
        "dnx451": {
            "dependencies": {
                "Microsoft.Framework.Logging.Serilog": "1.0.0-*"
            }
        },"dnxcore50": { }
    }
}

然后我想在我的Startup.cs中映射SignalR(因为我发现在git上的somwhere)

public void ConfigureServices(IServiceCollection services)
    {
        services.AddSignalR(options =>
        {
            options.Hubs.EnableDetailedErrors = true;
        });
    }

    public void Configure(IApplicationBuilder app,ILoggerFactory loggerFactory)
    {
#if DNX451
        string OutputTemplate = "{SourceContext} {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";

        var serilog = new LoggerConfiguration()
            .MinimumLevel.Verbose()
            .WriteTo.RollingFile(@".\SignalR-Log-{Date}.txt",outputTemplate: OutputTemplate);

        loggerFactory.AddSerilog(serilog);
#endif

        app.UseFileServer();

        app.UseSignalR<RawConnection>("/raw-connection");
        app.UseSignalR();
    }

,但当我在顶部添加

using Microsoft.AspNet.SignalR;

我收到错误

The type or namespace name ‘SignalR’ does not exist in the namespace >’Microsoft.AspNet’ (are you missing an assembly reference?) VersaWeb.ASP.NET >5.0 c:\Users\Jakub\documents\visual studio >2015\Projects\VersaWeb\src\VersaWeb\Startup.cs

我现在被困住了.

编辑:

问题必须与project.json有关,因为当我从音乐商店复制一个问题时,问题就消失了.

这是我当前的project.json(可能不需要一些依赖项,所以我将进一步测试它)

{
"authors": [
    "author"
],"description": "your description here","version": "1.0.0","compilationOptions": { "warningsAsErrors": true,"define": [ "DEMO","TESTING" ] },"code": [
    "**/*.cs"
],"bundleExclude": "*.cmd","webroot": "wwwroot","dependencies": {
    "EntityFramework.sqlServer": "7.0.0-beta3","EntityFramework.InMemory": "7.0.0-beta3",// For Mono.
    "Kestrel": "1.0.0-beta3","Microsoft.AspNet.Diagnostics": "1.0.0-beta3","Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta3","Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta3","Microsoft.AspNet.Mvc": "6.0.0-beta3","Microsoft.AspNet.Security.OpenIdConnect": "1.0.0-beta3","Microsoft.AspNet.Server.IIS": "1.0.0-beta3","Microsoft.AspNet.Server.WebListener": "1.0.0-beta3","Microsoft.AspNet.SignalR.Server": "3.0.0-beta3","Microsoft.AspNet.StaticFiles": "1.0.0-beta3","Microsoft.Framework.Cache.Memory": "1.0.0-beta3","Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta3","Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta3","Microsoft.Framework.Logging.Console": "1.0.0-beta3"
},"commands": {
    "gen": "Microsoft.Framework.CodeGeneration","kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004","run": "run server.urls=http://localhost:5003","web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002"
},"frameworks": {
    "aspnet50": { },"aspnetcore50": { }
}
}

解决方法

结帐 MusicStore sample,使用SignalR.我也在我的vnext项目中使用SignalR(尽管有kre,而不是新的dnx东西),所以它绝对可行.
原文链接:/csharp/244828.html

猜你在找的C#相关文章