TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
harry code
NA
124
22.7k
Chat Application using SignalR not working
Jan 31 2019 8:24 AM
Hi,
I am trying to develop a simple chat application in ASP.Net
i am using signalR.
the messages are not getting printed on the screen
Below is the .aspx code
<head id=
"Head1"
runat=
"server"
>
<title></title>
</head>
<body>
<form id=
"frmHome"
runat=
"server"
>
<div>
<ul id=
"ulInbox"
>
<li><span id=
"lblName"
>Name:</span> <span id=
"lblMessage"
>Message</span></li>
</ul>
<ul>
<li>
<input type=
"text"
id=
"txtMessage"
value=
""
/>
<input type=
"button"
id=
"btnSend"
value=
"Send"
/>
<input type=
"hidden"
id=
"txtName"
/>
</li>
</ul>
</div>
</form>
<script src=
"http://code.jquery.com/jquery-1.8.2.min.js"
type=
"text/javascript"
></script>
<script src=
"Scripts/jquery.signalR-1.0.1.min.js"
type=
"text/javascript"
></script>
<script src=
"signalr/hubs"
type=
"text/javascript"
></script>
<script type=
"text/javascript"
>
$(
function
() {
// Proxy created on the fly
var
chat = $.connection.chatHub;
// Get the user name and store it to prepend to messages.
$(
'#txtName'
).val(prompt(
'Enter your name:'
,
''
));
// Declare a function on the chat hub so the server can invoke it
chat.client.sendMessage =
function
(name, message) {
var
username = $(
'<div />'
).text(name).html();
var
chatMessage = $(
'<div />'
).text(message).html();
$(
'#ulInbox'
).append(
'<li>'
+ username +
': '
+ chatMessage +
'</li>'
);
};
// Start the connection
$.connection.hub.start().done(
function
()
{
$(
'#btnSend'
).click(
function
()
{
// Call the chat method on the server
chat.server.send($(
'#txtName'
).val(), $(
'#txtMessage'
).val());
$(
'#txtMessage'
).val(
''
);
});
});
});
</script>
</body>
</html>
This method should be called....but is is not getting called
public
class
ChatHub : Hub
{
public
void
Send(
string
name,
string
message)
{
Clients.All.sendMessage(name, message);
}
}
public
class
Global : System.Web.HttpApplication
{
void
Application_Start(
object
sender, EventArgs e)
{
// Code that runs on application startup
RouteTable.Routes.MapHubs();
}
}
Thank you
Reply
Answers (
3
)
How to incorporate dashboard template into asp.net mvc core
ASP.NET prevent videos & images from being downloaded