简体   繁体   中英

Signalr/hubs 404 with system.webServer/modules

I've an old website which is using customized url rewriting like below:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="URLHandler" type="Lib.URLHandler" preCondition="" />
    </modules>
</system.webServer>

Now when I add Signalr to this website, it gives me 404. Later I noticed that removing URLHandler module makes the Signalr working.

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
</system.webServer>

I cannot remove URLHandler as its managing lots of pages from a long time. So how can I make both Signalr and URLHandler work together?

It this because it cannot find the generated proxy ( signalr/hubs ) because of changing url? If so, try using own proxy (code without generated proxy) ie:

Instead of:

var contosoChatHubProxy = $.connection.contosoChatHub;

Use:

var connection = $.hubConnection();
var contosoChatHubProxy = connection.createHubProxy('contosoChatHub');

See examples without using generated proxy and read on here: http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client#genproxy

I've found a solution, in URLHandler I added a line that did the job for me.

void context_BeginRequest(object sender, EventArgs e)
  {
      if (HttpContext.Current.Request.Url.OriginalString.ToLower().Contains("signalr/hubs"))
           return;
      ..............
  }

I've also tried to work with generated proxy and it may work but its not as straight/helpful as chat hub like chatHub.server & chatHub.client isn't available and required to change the complete code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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