简体   繁体   English

Asp.Net MVC 4 app中的信号器

[英]Signalr in Asp.Net MVC 4 app

I'm working on Asp.net MVC app, I'd like to use signalr. 我正在使用Asp.net MVC应用程序,我想使用signalr。

Signalr to be hosted in IIS. 信号器将在IIS中托管。

I added the signalr dlls and added the reference to it. 我添加了信号器dll并添加了对它的引用。

In Global.asax , Global.asax中

I put the code, 我把代码,

inside Application_Start() Application_Start()中

 " RouteTable.Routes.MapHubs();"

I've pasted the Global.asax , 我贴了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();
    }
}

When i run the app, say, "http://localhost:4432" , 当我运行应用程序时,比如"http://localhost:4432"

When I try "http://localhost:4432/signalr/hubs" , I get exception as follows, 当我尝试"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 version : I tried with V1.1.25 and 2.0 信号器版本:我试过V1.1.25 and 2.0

Someone direct me what I should do to get it corrected? 有人指导我应该做些什么来纠正它?

1.write a hub extends Hub 1.write一个hub扩展Hub

public class MessageHub : Hub

2.check web.config 2.检查web.config

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

I tried, 我试过了,

  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();

}
}

Put "RouteTable.Routes.MapHubs();" 把“RouteTable.Routes.MapHubs();”放 in the first line of Application_Start() method. 在Application_Start()方法的第一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM