문제

I am building an instant chat module for the orchard project I am working on. I would like to use SignalR to power the chat, however I am running into difficulties with this:

<script src="@Url.Content("~/signalr/hubs")" type="text/javascript"></script>

I receive 404 error with everything I try. I have RAMFAR in webconfig, I have tried rewritting the url on IIS. I am hoping it is something horribly simple that my addled brain cant quite see. I don't even know for sure that SignalR works with Orchard, I suspected there would be some difficulties though

도움이 되었습니까?

해결책

It's much more tricky than @mdm described... SignalR uses a custom HttpModule that handles hubs. Unfortunately, due to dynamic loading of module assemblies there is no way to wire that HttpModule from a module without altering Orchard core.

Fortunately, I managed to sort things out and made a live demo with Orchard and SignalR playing nice together! Making it work was quite tricky and involved dropping the HttpModule in favor of a custom route implementation. I'll push the module to Orchard Gallery after doing some necessary cleanup and post an update here.

UPDATE: Module is nearly finished. There was a lot of changes in SignalR library since I started so needed to incorporate those. Also, there is one slight change to Orchard core (session handling) that I need to push before actually publishing the module.

UPDATE 2: SignalR uses Owin now so it's much easier to wire everything up. Orchard module is available here. You can also grab the latest code from BitBucket. Btw, I highly recommend using code from Orchard 1.x branch for SignalR development due to database transaction handling changes.

다른 팁

What is the URL that gets output on the page? What URL do you expect it to show?

Usually you would put the SignalR code in Scripts/signalr and reference scripts with the following at the top of your view:

@{
    Script.Include("signalr/script.js");
}

Or you could implement an IResourceManifestProvider in your module (Orchard.jQuery has a fantastic example of this, or see here), and then reference your scripts using Script.Require:

@{
    Script.Require("SignalR_Hubs");
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top