SignalR / hubs未找到错误 [英] SignalR/hubs not found error

查看:129
本文介绍了SignalR / hubs未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了Signalr Chat应用程序。聊天应用程序是单独运行的,但当我将其添加到现有的ASP.net应用程序时,它已停止工作。

以下是代码片段:



I developed the Signalr Chat Application. The Chat Application is running individually but when i added it to the existing ASP.net Application with the Master Pages it Stopped working.
Below is the code snippet:

SignalR Chat not working with the existing WebApp. Please help me with the solution.

I am able to run the Chat App using SignalR independently but after adding the files to the existing Web Application with Master Page, Chat session does not begin it stops working.I reinstalled SignalR Package many times removing it but the error still exists. Below is the code used:

ASPX:

<asp:Content ID="MyChatContent2" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">

    <script src="/Scripts/jquery-1.8.1.min.js" type="text/javascript"></script>
    <script src="/Bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.signalR-1.1.2.min.js"></script>
    <script src='/signalr/hubs' type="text/javascript"></script>
    <script src="/ChatJs/Scripts/jquery.activity-indicator-1.0.0.min.js" type="text/javascript"></script>
    <script src="/ChatJs/Scripts/jquery.chatjs.signalradapter.js" type="text/javascript"></script>
    <script src="/ChatJs/Scripts/jquery.chatjs.js" type="text/javascript"></script>
    <script src="/Scripts/scripts.js" type="text/javascript"></script>
    <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
    <!--Styles-->
    <link rel="stylesheet" type="text/css" href="/ChatJs/Styles/jquery.chatjs.css" />
    <link rel="stylesheet" type="text/css" href="/Bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/Bootstrap/css/bootstrap-responsive.min.css" />

    <% if (!this.IsUserAuthenticated)
       { %>
    <script type="text/javascript">
        function notAutho() {
            aler("not autoh.....");
        }
    &lt;/script>
    <% } %>


    <% if (this.IsUserAuthenticated)
       { %>
    &lt;script type="text/javascript">
        //$.connection.hub.start();

        //$.connection.hub.url = "/signalr"
        //$.connection.hub.start().done(init);

        var connection = $.hubConnection("/signalr", { useDefaultPath: false });

        $(function () {
            debugger;
            alert("chat is authenticated..");
            $.chat({
                // your user information
                user: {
                    Id: '<%= this.UserId %>',
                    Name: '<%= this.UserName %>',
                    ProfilePictureUrl: '/ChatJs/Images/spotlight photo.png'
                },
                // text displayed when the other user is typing
                typingText: ' is typing...',
                // the title for the user's list window
                titleText: 'Chat',
                // text displayed when there's no other users in the room
                emptyRoomText: "There's no one around here. You can still open a session in another browser and chat with yourself :)",
                // the adapter you are using
                adapter: new SignalRAdapter()
            });
        });

    &lt;/script>
    <% } %>
<%--&lt;/head>

        &lt;script type="text/javascript">
            $(document).ready(function () {
                //joinChatwithHandler();
            });
            function joinChatwithHandler() {
                alert("joinChatConclusionButton calling............ ");
                var $userName = $("#userName");
                var $empID = $("#empID");

                if (!$userName.val() || $userName.val() == $userName.attr("placeHolder")) {
                    $userName.closest(".control-group").addClass("error");
                }
                else {
                    alert("handler is calling............ ");
                    $.ajax({
                        url: "../Handlers/ChatService.ashx?action=joinChat&userName=" + $userName.val() + "&empID=" + $empID.val(),
                        success: function (data) {
                            window.location.reload(false);
                        }
                    });
                }
            }
        &lt;/script>
<%--    &lt;/form>
&lt;/body>
&lt;/html>--%>
</asp:Content>

.CS:
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                LoadChat();
            }
            catch
            {
            }
        }
        private void LoadChat()
        {
            try
            {
                userName.Value = Convert.ToString(Session[SessionVariables.FullName]);
                empID.Value = Convert.ToString(Session[SessionVariables.emplSequ]);

                if (Session[SessionVariables.isChatHandler] == null)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "chat", "joinChatwithHandler();", true);
                    Session[SessionVariables.isChatHandler] = "Y";
                }

                if (Session[SessionVariables.isUserExists] == null)
                {
                    var existingUser = ChatCookieHelperStub.GetDbUserFromCookie(new HttpRequestWrapper(this.Request));
                    if (existingUser != null)
                    {
                        //Session["Name"] = existingUser.FullName;
                        //Session["id"] = existingUser.Id;
                        Session[SessionVariables.isUserExists] = "Y";
                        IsUserAuthenticated = true;
                        UserId = Convert.ToInt32(Session[SessionVariables.emplSequ]);
                        UserName = Convert.ToString(Session[SessionVariables.FullName]);
                        UserProfilePictureUrl = "/ChatJs/Images/spotlight photo.png";
                    }
                }
            }
            catch
            {
            }


Startup.cs:

using System.Security.Cryptography;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(HRMSUI.Startup))]
namespace HRMSUI
{
    public static class Startup
    {
        public static void Configuration(IAppBuilder app)
        {
            try
            {
                CryptoConfig.AddAlgorithm(typeof(SHA256Cng), "System.Security.Cryptography.SHA256");
                //app.MapSignalR();

                var hubConfiguration = new HubConfiguration();
                hubConfiguration.EnableDetailedErrors = true;
                hubConfiguration.EnableJavaScriptProxies = false;
                app.MapSignalR("/signalr", hubConfiguration);
            }
            catch
            {
            }
        }
    }
}


Route.config:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Routing;
using Microsoft.AspNet.FriendlyUrls;

namespace HRMSUI
{
    public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            try
            {
                var settings = new FriendlyUrlSettings();
                settings.AutoRedirectMode = RedirectMode.Permanent;
                routes.EnableFriendlyUrls(settings);
            }
            catch
            {
            }
        }
    }
}


Web.Config:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
  <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
  <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
  <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
  <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" />
  </sectionGroup>
  </configSections>
  <appSettings>
    <add key="owin:AppStartup" value="HRMSUI.Startup" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />

    <httpRuntime targetFramework="4.5" />
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>

    <controls>
      <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
    <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" /></controls></pages>
    <authentication mode="Forms">
      &lt;forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNet.SignalR.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.3.0" newVersion="2.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="HtmlAgilityPack" publicKeyToken="bd319b19eaf3b43a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.4.0.0" newVersion="1.4.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.4" newVersion="2.1.0.4" />
      </dependentAssembly>
      <dependentAssembly>
        <!--<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />-->
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
</runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  <!-- For Signalr-->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true">
      </modules>
    </system.webServer>
</configuration>



I get the below error when i try running the Project:

Error Caught in
Error in: http://localhost:2256/signalr/hubs
Main Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow()
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
   at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Base Exception : System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow()
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
   at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Please help me with the solution.

推荐答案

.connection.hub.start();

//
.connection.hub.start(); //


.connection.hub.url = \"/signalr\"
//
.connection.hub.url = "/signalr" //


.connection.hub.start().done(init);

var connection =
.connection.hub.start().done(init); var connection =


这篇关于SignalR / hubs未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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