MVC4 SignalR" signalr /集线器" 501未执行错误 [英] MVC4 SignalR "signalr/hubs" 501 Not Implemented Error

查看:174
本文介绍了MVC4 SignalR" signalr /集线器" 501未执行错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:
切换到IIS防爆preSS,而不是在Visual Studio开发服务器固定的501错误。

我试图让SignalR在我MVC4申请工作,但我遇到了一个奇怪的501错误。我跟了几个不同的教程,但结果总是一样的。

任何帮助将是AP preciated。

我使用Visual Studio 2012临,我通过包管理器控制台安装SignalR 0.5.1。

我的code:

布局

 <脚本SRC =〜/脚本/ jQuery的-1.7.2.min.js>< / SCRIPT>
<脚本SRC =〜/脚本/ jquery.signalR-0.5.1.js类型=文/ JavaScript的>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =@ Url.Content(〜/ signalr /中心)>< / SCRIPT>

查看

 <脚本类型=文/ JavaScript的>
$(函数(){    //获取客户端IP
    。VAR clientIp = $(#clientip)VAL();    //创建SignalR代理
    VAR userlink = $ .connection.userlink;    //创建我们的回调代理
    userlink.updateViewCount =功能(消息){
        $('#视图更新)HTML('< P>'+信息+'< / P>')。
    };    //开始连接
    $ .connection.hub.start(函数(){
        //把我们的记录消息中心
        userlink.recordView(clientIp);
    });});
< / SCRIPT><输入类型=隐藏ID =客户端IPVALUE =@ ViewBag.ClientIpAddress/>
< D​​IV ID =视图更新>< / DIV>

集线器类

 公共类UserLink:集线器
{
    公共无效RecordView(字符串Ip地址)
    {
        QContext DB =新QContext();
        db.SiteVisits.Add(新现场访问{CREATEDATE = DateTime.Now,ip地址= Ip地址});
        db.SaveChanges();        INT = USERCOUNT db.SiteVisits.Count();        字符串结果=的String.Format(已经有{0}访问这个网页。USERCOUNT位);        Clients.updateViewCount(结果);
    }
}

我收到错误

 无法加载资源:服务器用501(未实现)HTTP的状态回应://本地主机:58361 / signalr /集线器
未捕获类型错误:未定义无法设置属性updateViewCount


解决方案

调试在IIS中,而不是在Visual Studio开发服务器解决这个问题,但我不知道为什么。现在我很好奇,如果任何人知道为什么它会在一个工作,而不是其他。

Update: Switching to IIS Express instead of the Visual Studio Development Server fixed the 501 error.

I'm trying to get SignalR working in my MVC4 application but I am running into a strange 501 error. I have followed a couple different tutorials but the result is always the same.

Any help would be appreciated.

I am using Visual Studio 2012 Pro RC and I installed SignalR 0.5.1 through the package manager console.

My code:

Layout

<script src="~/Scripts/jquery-1.7.2.min.js"></script>
<script src="~/Scripts/jquery.signalR-0.5.1.js" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/signalr/hubs")"></script>

View

<script type="text/javascript">
$(function () {

    // capture the client IP
    var clientIp = $("#clientip").val();

    // create the SignalR proxy
    var userlink = $.connection.userlink;

    // create our callback for the proxy
    userlink.updateViewCount = function (message) {
        $('#view-updates').html('<p>' + message + '</p>');
    };

    // Start the connection
    $.connection.hub.start(function () {
        // send our 'record' message to the hub
        userlink.recordView(clientIp);
    });

});
</script>

<input type="hidden" id="client-ip" value="@ViewBag.ClientIpAddress" />
<div id="view-updates"></div>

Hub Class

public class UserLink : Hub
{
    public void RecordView(string IpAddress)
    {
        QContext db = new QContext();
        db.SiteVisits.Add(new SiteVisit { CreateDate = DateTime.Now, IpAddress = IpAddress });
        db.SaveChanges();

        int userCount = db.SiteVisits.Count();

        string result = string.Format("There have been {0} visits to this page.", userCount);

        Clients.updateViewCount(result);
    }
}

Error I am receiving

Failed to load resource: the server responded with a status of 501 (Not Implemented) http://localhost:58361/signalr/hubs
Uncaught TypeError: Cannot set property 'updateViewCount' of undefined 

解决方案

Debugging in IIS instead of the Visual Studio Development Server fixes the issue, but I'm not sure why. Now I'm curious if anyone knows why it would work in one and not the other.

这篇关于MVC4 SignalR&QUOT; signalr /集线器&QUOT; 501未执行错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆