2013-07-02 3 views
20

मैं इस नई परियोजना में काम करने के लिए यह tutorial प्राप्त कर सकता हूं, लेकिन मेरे मौजूदा प्रोजेक्ट में नहीं।सिग्नलआर:/सिग्नलर/हब्स उत्पन्न नहीं होते

मेरे परियोजना web.config फ़ाइल में निम्न विशेषता के साथ एक ASP.Net MVC 4 वेब अनुप्रयोग है:

<appSettings> 
    <add key="webpages:Enabled" value="true"/> 
</appSettings> 

इसका कारण यह है अपने आवेदन एक एकल-पृष्ठ-आवेदन, जिस पर AngularJS का उपयोग करता है ग्राहक पक्ष। अपने आवेदन में केवल पेज index.cshtml, जो मैं signalR के लिए प्रासंगिक कोड जोड़ दिया है:

public class ChatHub : Hub 
{ 
    public void Send(string name, string message) 
    { 
     // Call the broadcastMessage method to update clients. 
     Clients.All.broadcastMessage(name, message); 
    } 
} 

और अंत में:

<!-- signalR chat --> 
<script src="~/Scripts/jquery.signalR-1.0.0.js"></script> 
<!--Reference the autogenerated SignalR hub script. --> 
<script src="/signalr/hubs"></script> 
<!--Add script to update the page and send messages.--> 
<script type="text/javascript"> 
    $(function() { 
     // Declare a proxy to reference the hub. 
     var chat = $.connection.chatHub; 
     // Create a function that the hub can call to broadcast messages. 
     chat.client.broadcastMessage = function (name, message) { 
      // Html encode display name and message. 
      var encodedName = $('<div />').text(name).html(); 
      var encodedMsg = $('<div />').text(message).html(); 
      // Add the message to the page. 
      $('#discussion').append('<li><strong>' + encodedName 
       + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>'); 
     }; 
     // Get the user name and store it to prepend to messages. 
     $('#displayname').val(prompt('Enter your name:', '')); 
     // Set initial focus to message input box. 
     $('#message').focus(); 
     // Start the connection. 
     $.connection.hub.start().done(function() { 
      $('#sendmessage').click(function() { 
       // Call the Send method on the hub. 
       chat.server.send($('#displayname').val(), $('#message').val()); 
       // Clear text box and reset focus for next comment. 
       $('#message').val('').focus(); 
      }); 
     }); 
    }); 
</script> 

तब मैं ChatHub.cs फ़ाइल मिल गया है Global.asax में:

protected void Application_Start() 
    { 
     RouteTable.Routes.MapHubs(); 
     BundleConfig.RegisterBundles(BundleTable.Bundles); 
    } 

जब मैं आवेदन चलाने के लिए,/signalr/केन्द्रों फ़ाइल उत्पन्न नहीं है। जब फ़ाइल का अनुरोध करते समय मुझे 404 मिलता है, और यह लाइन पर दुर्घटनाओं:

chat.client.broadcastMessage = function (name, message) { .... 

क्योंकि चैट अशक्त के रूप में पिछली लाइन भी नहीं मिला है chatHub:

var chat = $.connection.chatHub; 

किसी को भी पता है क्या गलत है मेरी कोड?

अद्यतन

मैं लाइन ::

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

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

उत्तर

15

को बदलकर मेरी समस्या हल है मैं मेरी समस्या हल है लाइन बदलकर ::

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

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

बीटीडब्ल्यू, '/ सिग्नलर/हब्स 'परियोजना में एक फ़ाइल नहीं है। अगर किसी को ढूंढने में समय बर्बाद करने का लुत्फ उठाया जाता है। यदि आप ऐप लॉन्च करते हैं तो उस यूआरएल पर जाएं, यह आपको दिखाएगा। – toddmo

+0

@toddmo, इसका मतलब क्या है कि यह फ़ाइल नहीं है? , मैंने एक वास्तविक समय अधिसूचना प्रणाली विकसित की है और यह $ .connection.hub.start() का आविष्कार नहीं कर रहा है। मुझे लगता है कि ~/सिग्नल/हब्स को इसके साथ कुछ करना है क्योंकि पैकेज को जोड़ने के बाद भी समाधान में कहीं भी नहीं है – Saurabh

+0

@toddmo, टिप्पणी पोस्ट करने के लिए खेद है क्योंकि मैं एक ही प्रश्न फिर से पोस्ट नहीं करना चाहता, मेरी रूट निर्देशिका http: // localhost है: 56547/होम/इंडेक्स, क्या आप http: // localhost: 56547/सिग्नल/हब्स पर जाने का सुझाव दे रहे हैं ?? – Saurabh

1

को मैं एक ऐसी ही समस्या जहां केन्द्रों फ़ाइल उत्पन्न नहीं किया जा रहा था। ऐसा लगता है कि ओपी following the steps here था। जिस तरह से मैंने समस्या को हल किया वह jquery के साथ करना था। नीचे लिंक किया गया ट्यूटोरियल jquery 1.6.4 और jquery-signalr संस्करण 2.1.0 के साथ लिखा गया था। जब विजुअल स्टूडियो ने मेरे लिए स्क्रिप्ट फ़ोल्डर जेनरेट किया, तो उसने jquery संस्करण 1.10.2 और jquery-signalr संस्करण 2.0.2 का उपयोग किया।

जिस तरह से मैंने इसे ठीक किया था, बस index.html फ़ाइल को संपादित करना था। ध्यान दें कि आप त्रुटियों को देखने के लिए क्रोम की जावास्क्रिप्ट कंसोल विंडो Ctrl + Shift + J का उपयोग कर सकते हैं।

3

इसके अलावा, क्यों कारण/सिग्नल/हब उत्पन्न नहीं होते हैं, ओविन स्टार्टअप कॉन्फ़िगरेशन में मानचित्र सिग्नलर को भूल जाते हैं।

public class Startup 
{ 
    public void Configuration(IAppBuilder appBuilder){ 
     ... 
     appBuilder.MapSignalR(); 
     ... 
    } 
... 
2

मेरे मामले में, ऐसा इसलिए था क्योंकि मेरी चैटहब कक्षा को सार्वजनिक रूप से चिह्नित नहीं किया गया था।

0

मैं यह जोड़ना चाहूंगा कि सिग्नलआर रीडमे फ़ाइल में इस मुद्दे के बारे में कुछ नोट है। और यदि आपका सिग्नलआर पृष्ठ आंशिक दृश्य में है तो कुछ स्क्रिप्ट मास्टर पेज में होनी चाहिए।

Please see http://go.microsoft.com/fwlink/?LinkId=272764 for more information on using SignalR. 

Upgrading from 1.x to 2.0 
------------------------- 
Please see http://go.microsoft.com/fwlink/?LinkId=320578 for more information on how to 
upgrade your SignalR 1.x application to 2.0. 

Mapping the Hubs connection 
---------------------------- 
To enable SignalR in your application, create a class called Startup with the following: 

using Microsoft.Owin; 
using Owin; 
using MyWebApplication; 

namespace MyWebApplication 
{ 
    public class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
      app.MapSignalR(); 
     } 
    } 
} 

Getting Started 
--------------- 
See http://www.asp.net/signalr/overview/getting-started for more information on how to get started. 

Why does ~/signalr/hubs return 404 or Why do I get a JavaScript error: 'myhub is undefined'? 
-------------------------------------------------------------------------------------------- 
This issue is generally due to a missing or invalid script reference to the auto-generated Hub JavaScript proxy at '~/signalr/hubs'. 
Please make sure that the Hub route is registered before any other routes in your application. 

In ASP.NET MVC 4 you can do the following: 

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

If you're writing an ASP.NET MVC 3 application, make sure that you are using Url.Content for your script references: 

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

If you're writing a regular ASP.NET application use ResolveClientUrl for your script references or register them via the ScriptManager 
using a app root relative path (starting with a '~/'): 

    <script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script> 

If the above still doesn't work, you may have an issue with routing and extensionless URLs. To fix this, ensure you have the latest 
patches installed for IIS and ASP.NET. 
0

मेरे लिए समाधान सभी संकुल को पुनर्स्थापित और सभी dependecies बहाल करने के लिए किया गया था।

ओपन न्यूज पावरहेल कंसोल खोलें और इस कमांड का उपयोग करें।

Update-Package -Reinstall 
संबंधित मुद्दे