ASP.NET MVC with SignalR - Client Undefined Error

While working on a new ASP.NET MVC layer sample with SignalR, I have constantly encountered the following error when I tried to access the site directly with the full path to the View i.e. http://localhost:13618/Home/Index

0x800a138f - JavaScript runtime error: Unable to get property 'client' of undefined or null reference

This error does not occur when I access the path to the site i.e. http://localhost:13618/

My Views are using a layout and it has all the SignalR javascript references defined.

Index.cshtml

@{
    ViewBag.Title = "Apply Leave";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

_Layout.cshtml

<head>
    <meta name="viewport" content="width=device-width" />
    <title>Layered Architecture Sample for .NET</title>
    <script src="~/Scripts/jquery-2.1.0.min.js"></script>
    <script src="~/Scripts/jquery-ui-1.10.3.min.js"></script>
    <script src="~/Scripts/jquery.signalR-2.0.3.min.js"></script>
    <script src="signalr/hubs"></script>
    <link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
    <link href="~/Content/Site.css" rel="stylesheet" />
</head>
It turns out that I was using the wrong way to reference the hub scripts in ASP.NET MVC. The problem can be easily resolved by changing the following line in the _layout.cshtml page from

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

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

*Slaps myself for not reading the documentation properly*

No comments:

Post a Comment

Popular Post