Answered by:
Need help with SignalRChat

Question
-
User-1402564948 posted
Hello, I'm trying to add SR to my existing application.
My first problem was that the SR Startup class conflicts with my Owin Startup Class. The only way I could get it to work was to disable the Owin Startup Class.
My next issue is that I go to the index.html and it doesn't prompt me for a name. It just shows the chat page.
Imports System.Web Imports Microsoft.AspNet.SignalR Namespace SignalRChat Public Class ChatHub Inherits Hub Public Sub Send(name As String, message As String) ' Call the broadcastMessage method to update clients. Clients.All.broadcastMessage(name, message) End Sub End Class End Namespace
Imports Microsoft.Owin Imports Owin Imports sfa <Assembly: OwinStartup(GetType(SignalRChat.Startup))> Namespace SignalRChat Public Class Startup Public Sub Configuration(app As IAppBuilder) ' Any connection or hub wire up and configuration should go here app.MapSignalR() End Sub End Class End Namespace
<!DOCTYPE html> <html> <head> <title>SignalR Simple Chat</title> <style type="text/css"> .container { background-color: #99CCFF; border: thick solid #808080; padding: 20px; margin: 20px; } </style> </head> <body> <div class="container"> <input type="text" id="message" /> <input type="button" id="sendmessage" value="Send" /> <input type="hidden" id="displayname" /> <ul id="discussion"></ul> </div> <!--Script references. --> <!--Reference the jQuery library. --> <script src="Scripts/jquery-1.6.4.min.js"></script> <!--Reference the SignalR library. --> <script src="Scripts/jquery.signalR-2.1.0.min.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>: ' + 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> </body> </html>
Thursday, June 2, 2016 4:02 PM
Answers
-
User61956409 posted
Hi dvdgzzrll,
the SR Startup class conflicts with my Owin Startup Class. The only way I could get it to work was to disable the Owin Startup Class.This link discussed a similar issue, you could refer to it.
http://stackoverflow.com/questions/22608019/owinstartup-and-startup-in-signalr-in-asp-net-mvc
I go to the index.html and it doesn't prompt me for a name. It just shows the chat page.// Get the user name and store it to prepend to messages.$('#displayname').val(prompt('Enter your name:', ''));
The prompt() method displays a dialog box that prompts the user for input, please make sure if you call the prompt() method in your index page.
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 3, 2016 5:21 AM
All replies
-
User61956409 posted
Hi dvdgzzrll,
the SR Startup class conflicts with my Owin Startup Class. The only way I could get it to work was to disable the Owin Startup Class.This link discussed a similar issue, you could refer to it.
http://stackoverflow.com/questions/22608019/owinstartup-and-startup-in-signalr-in-asp-net-mvc
I go to the index.html and it doesn't prompt me for a name. It just shows the chat page.// Get the user name and store it to prepend to messages.$('#displayname').val(prompt('Enter your name:', ''));
The prompt() method displays a dialog box that prompts the user for input, please make sure if you call the prompt() method in your index page.
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 3, 2016 5:21 AM -
User-1402564948 posted
Thanks for your reply.
Should I install it right into the root of my solution or should I create a new virtual directory / folder?
Monday, July 4, 2016 4:26 PM