【问题标题】:using SignalR and angularjs on Asp.Net 4.0在 Asp.Net 4.0 上使用 SignalR 和 angularjs
【发布时间】:2016-01-04 14:15:56
【问题描述】:

在我过去两天在谷歌搜索没有任何进展后,我求助于这里问这个问题。这是我的挑战:我有一个使用 Angularjs 的 Asp.Net 4.0 应用程序{我基本上只使用 Html 页面}。我需要将 SignalR 集成到项目中以进行实时通信。我用谷歌搜索过,我看到的只是上面带有 .Net 4.5 的示例。我无法使用其中任何一个,因为我的服务提供商不支持 .net 4.5,因此无法成功托管应用程序。

我的挑战在于这条线

[assembly: OwinStartupAttribute(typeof(SignalRwithAngular.Startup))]

尝试设置 Startup 类时。因为它抱怨

Error   18  The type or namespace name 'OwinStartupAttribute' could not be found (are you missing a using directive or an assembly reference?)  

我只需要一个示例,说明如何配置我的 angularjs 控制器以与 Hub 通信,以及如何为 .Net 4.0 设置 Startup 类 请注意,我不能使用 .Net 4.5,因为我的主机不支持它。

任何有用的链接将不胜感激。

【问题讨论】:

    标签: angularjs .net-4.0 signalr


    【解决方案1】:

    您是否包含 Microsoft.Owin 作为参考(通过 NuGet)?

    【讨论】:

    • 是的,我同时拥有 Microsoft.Owin 和使用 Owin
    【解决方案2】:

    经过多次谷歌搜索,我终于找到了出路 我完全删除了

    [assembly: OwinStartupAttribute(typeof(SignalRwithAngular.Startup))]
    

    从启动类

    我通过 nuget 为 .Net 4.0 安装了 SignalR 1.1.4 包

    Install-Package Microsoft.AspNet.SignalR.Client -Version 1.1.4
    

    在我的 Global.asax 中

     protected void Application_Start()
        {
    
            RouteTable.Routes.MapHubs();   // Must be added as the first line
             // Other Configs go here
        }
    

    在我的 Startup.cs 中

    public  class Startup
    {
      public void Configuration(IAppBuilder app)
      {
          app.MapHubs();
      }
    
    }
    

    我在构建后通过导航到

    确认了它
    http://localhost:port/signalr/hubs
    

    现在一切正常......

    【讨论】:

      猜你喜欢
      • 2018-07-08
      • 2014-11-05
      • 2011-04-07
      • 2017-09-13
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 2011-12-20
      • 1970-01-01
      相关资源
      最近更新 更多