【问题标题】:Signalr in Asp.Net MVC 4 appAsp.Net MVC 4 应用程序中的 Signalr
【发布时间】:2014-01-10 18:34:45
【问题描述】:

我正在开发 Asp.net MVC 应用程序,我想使用 signalr。

Signalr 托管在 IIS 中。

我添加了信号器 dll 并添加了对它的引用。

Global.asax 中,

我把代码,

Application_Start()

 " RouteTable.Routes.MapHubs();"

我已经粘贴了 Global.asax

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Http;
  using System.Web.Mvc;
  using System.Web.Optimization;
  using System.Web.Routing;

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();
        RouteTable.Routes.MapHubs();
    }
}

当我运行应用程序时,比如说"http://localhost:4432"

当我尝试"http://localhost:4432/signalr/hubs" 时,我得到如下异常,

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /signalr/hubs

Signalr 版本:我试过V1.1.25 and 2.0

有人指导我应该怎么做才能纠正它?

【问题讨论】:

  • 您使用的是什么版本的 SignalR?
  • 我也想问同样的问题,请分享您的 signalR 版本。那里有大量“如何开始使用 signalR”教程,请寻找与您使用相同版本的教程。
  • @SoonDead 我试过了,版本 1.1.25 和版本 2.0...
  • 您尝试将using Microsoft.AspNet.SignalR; 添加到您的命名空间吗?
  • @Tim B James In Global.asax?

标签: asp.net-mvc asp.net-mvc-4 signalr signalr-hub signalr.client


【解决方案1】:

1.写一个集线器扩展集线器

public class MessageHub : Hub

2.检查web.config

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">

【讨论】:

  • 我试过了,仍然得到,异常,............“/”应用程序中的服务器错误。无法找到该资源。说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。请求的 URL:/signalr/hubs
  • 尝试移动 RouteTable.Routes.MapHubs();到第一行;如果它与 mvc 或 web api 路由有相同的冲突,我不记得了
【解决方案2】:

我试过了,

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Http;
  using System.Web.Mvc;
  using System.Web.Optimization;
  using System.Web.Routing;

  public class MvcApplication : System.Web.HttpApplication
  {
  protected void Application_Start()
   {
    RouteTable.Routes.MapHubs();
    AreaRegistration.RegisterAllAreas();

    WebApiConfig.Register(GlobalConfiguration.Configuration);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    AuthConfig.RegisterAuth();

}
}

输入“RouteTable.Routes.MapHubs();”在 Application_Start() 方法的第一行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-31
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多