0
votes

I have a project that uses SignalR (uses tutorial from https://gkulshrestha.wordpress.com/2014/05/02/signalr-with-sql-server-query-notification/) When I run it from visual studio, my project works perfectly. However, when I run it on a server (after having published it and with IIS), it doesn't work.

Specifically, I found out that a certain part of the JS is not running. I have

@section Scripts{
    <script src="/Scripts/jquery.signalR-2.1.1.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="/signalr/hubs"></script>
    <script type="text/javascript">
        $(function () {
            // Reference the auto-generated proxy for the hub.
            alert(1);
            var clientHub = $.connection.messageSender;
            alert(5);
            // Create a function that the hub can call back to display messages.
            clientHub.client.broadcastMessage = function (message) {
                // Add the message to page.
                $('#messagecontainer').append('<li>' + message + '</li>');
            };
            alert(2);
            $.connection.hub.start().done(function () {
                alert("connection started")
            }).fail(function (e) {
                alert(e);
            });
            alert(3);

        });

    </script>
}

When running this through visual studio, I hit all the alerts in here. When running it on the server (by pressing Browse), I only hit alert(1) and none of the others.

Any help would be appreciated! Thanks!

[edit] I've looked around and I'm suspecting it has to do with my signalr/hubs reference. I've tried everything on SignalR /signalr/hubs 404 Not Found but no luck.

1
What does the F12 debug window tell you?Nick.McDermaid

1 Answers

2
votes

Try using helpers when including static resources:

<script src="@Url.Content("~/Scripts/jquery.signalR-2.1.1.js")"></script>

and:

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

This will take into account the virtual directory in which your application might be running in IIS. Also if you are using the latest Razor you could just prefix with ~ to indicate the relative path:

<script src="~/Scripts/jquery.signalR-2.1.1.js"></script>

and:

<script src="~/signalr/hubs"></script>