Signalr集线器未找到(403) [英] Signalr Hubs Not found (403)

查看:1223
本文介绍了Signalr集线器未找到(403)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,所以我已经看到了关于这个问题的负荷,但没有建议的修复已经为我工作。

Right, so I've seen loads of questions about this, but none of the suggested fixes have worked for me.

我有一个MVC4项目在Visual Studio 2012上运行/ IIS防爆preSS,使用SignalR做一些反馈给用户。当我运行的项目,我在Chrome中像这样得到一个403错误:

I have a MVC4 project running in Visual Studio 2012/IIS Express, using SignalR to do some feedback to users. When I run the project I get a 403 error in Chrome like such:

Failed to load resource: the server responded with a status of 403 (Forbidden) http://{website}/Hubs/


Uncaught Error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/hubs'></script>.

显然,我已经改变了实际的域在我的机器上{}网站

Obviously I've changed the actual domain on my machine to {website}

现在,我原本是一个名为signalr与集线器的子文件夹我的web项目的根文件夹中,但后来我在GitHub上SignalR,你不应该这样做阅读,所以我改成了只是'枢纽。还是剪掉修复它。

Now, originally I had it in a folder called signalr in the root of my web project with a subfolder of hubs, but then I read on the SignalR GitHub that you shouldn't do that, so i changed it to just 'Hubs'. Still didnt fix it.

我也看到了有关把你的RouteTable.Routes.MapHubs修复();正确的顺序。我的是这样的:

I've also seen the fix regarding putting your RouteTable.Routes.MapHubs(); in the right order. Mine looks like this:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RouteTable.Routes.MapHubs();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

我也看到一些人在暗示你的路线作为参数传递到MapHubs()方法,但是这需要一个字符串和HubConfiguration对象作为参数,以便不工作无论是。

I've also seen some people suggesting passing in your route as a parameter into the MapHubs() method, but that takes a string and a HubConfiguration object as a parameter so that's not working either.

我的看法code是这样的:

My view code looks like this:

@using(Html.BeginForm("Report", "Home", FormMethod.Post, new { enctype="multipart/form-data" }))
{
    @Html.ValidationSummary(true);
    <div>
        @(InputExtensions.Hidden(Html, "submittingUserId", ViewBag.CurrentUser))
        @(InputExtensions.Hidden(Html, "signalConnectionId"))
        <br />
        @Html.EditorFor(model => model.UploadedFile)
        @Html.ValidationMessageFor(model => model.UploadedFile)
    </div>
    <div>
        <input id="subButton" type="submit" value="UploadFile" title="Upload File" />
    </div>
}

@section Scripts {
    @Scripts.Render("~/Scripts/jquery.signalR-1.1.1.min.js")
    @Scripts.Render("~/Hubs")

    <script type="text/javascript">
        $(document).ready(function () {
            var accountMovementMoveHub = $.connection.accountMovementHub;
            $("#signalConnectionId").val($.connection.connectionId);

            $.connection.hub.updateProgress = function (message) {
                $("#progress-list").append('<li>' + message + '</li>');

            };

            $.connection.hub.start();
        });
    </script>

}

我还添加这些元素到web.config:

I've also added these elements to the web.config:

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

它是推动我绝对疯了,我已经试过绝对每一个建议我能找到这里,github上,和其他任何地方为此事:(

It's been driving me absolutely insane, I've tried absolutely every suggestion I could find on here, github, and anywhere else for that matter :(

任何帮助将大大AP preciated!

Any help would be greatly appreciated!

感谢

答案

因此​​,原来,我假定脚本引用/ signalr /集线器是包含集线器的物理文件夹。它不是;它是一个虚拟目录,这就是为什么如果你也有叫SignalR一个物理文件夹就迷糊的参考。我动了我的文件夹中的集线器到我的创业项目,并设置脚本引用回/ signalr /中心,这一切开始工作。

So it turns out, I assumed that the script reference to /signalr/hubs was to the PHYSICAL folder containing the hubs. Which it isn't; it is a reference to a virtual directory, which is why if you ALSO have a physical folder called SignalR it gets confused. I moved my hubs folder to my business project, and set the script reference back to "/signalr/hubs" and it all started working.

很抱歉的愚蠢的问题,并感谢你的答案。

Sorry about the stupid question and thanks for your answers.

推荐答案

RouteTable.Routes.MapHubs();你的集线器映射到http:// {}网站/ signalr /集线器

RouteTable.Routes.MapHubs(); maps your hubs to http://{website}/signalr/hubs

为什么你试图让从http枢纽:// {}网站/集线器?
只需访问您的浏览器的两条路径,你需要获得包含大量的JavaScript code的HTTP响应。如果还是不行,那么就意味着你的应用程序未配置正确。

Why are you trying to get the hubs from http://{website}/Hubs? Simply access both paths from your browsers, you need to get a http response containing a lot of javascript code. If that does not work, then it means your application is not configured right.

按照此<一个href=\"http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc-4\"相对=nofollow>教程,你可以看到RouteTable.Routes.MapHubs(顺序)比你的有什么不同。

Follow this tutorial, you can see the order of RouteTable.Routes.MapHubs() is different than what your have

这篇关于Signalr集线器未找到(403)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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