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
louis Tunde
NA
278
62.5k
Chat Application
Oct 11 2019 5:41 AM
Please I need help
I am creating a chat application in ASP.NET C#. I used the step by Altaf Ansari on Signal R Chat App with Webform and Bootstrap - Part One.
I used the code in the chatHub Class by the code display error in the following
1. Context
2. Clients
3. OnDisconnected
The complete code is displayed below
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
Microsoft.AspNet.SignalR;
namespace
CHAPP_WEB
{
public
class
ChutHub
{
static
List ConnectedUsers =
new
List();
static
List CurrentMessage =
new
List();
ConnClass ConnC =
new
ConnClass();
public
void
Connect(
string
userName)
{
var id = Context.ConnectionId;
if
(ConnectedUsers.Count(x => x.ConnectionId == id) == 0)
{
string
UserImg = GetUserImage(userName);
string
logintime = DateTime.Now.ToString();
ConnectedUsers.Add(
new
Users { ConnectionId = id, UserName = userName, UserImage = UserImg, LoginTime = logintime });
// send to caller
Clients.Caller.onConnected(id, userName, ConnectedUsers, CurrentMessage);
// send to all except caller client
Clients.AllExcept(id).onNewUserConnected(id, userName, UserImg, logintime);
}
}
public
void
SendMessageToAll(
string
userName,
string
message,
string
time)
{
string
UserImg = GetUserImage(userName);
// store last 100 messages in cache
AddMessageinCache(userName, message, time, UserImg);
// Broad cast message
Clients.All.messageReceived(userName, message, time, UserImg);
}
private
void
AddMessageinCache(
string
userName,
string
message,
string
time,
string
UserImg)
{
CurrentMessage.Add(
new
Messages { UserName = userName, Message = message, Time = time, UserImage = UserImg });
if
(CurrentMessage.Count > 100)
CurrentMessage.RemoveAt(0);
// Refresh();
}
public
string
GetUserImage(
string
username)
{
string
RetimgName =
"images/dummy.png"
;
try
{
string
query =
"select Photo from tbl_Users where UserName='"
+ username +
"'"
;
string
ImageName = ConnC.GetColumnVal(query,
"Photo"
);
if
(ImageName !=
""
)
RetimgName =
"images/DP/"
+ ImageName;
}
catch
(Exception ex)
{ }
return
RetimgName;
}
public
override
System.Threading.Tasks.Task OnDisconnected(
bool
stopCalled)
{
var item = ConnectedUsers.FirstOrDefault(x => x.ConnectionId == Context.ConnectionId);
if
(item !=
null
)
{
ConnectedUsers.Remove(item);
var id = Context.ConnectionId;
Clients.All.onUserDisconnected(id, item.UserName);
}
return
base
.OnDisconnected(stopCalled);
}
}
}
Please help me out.
Thanks
Reply
Answers (
2
)
Web Site Log Out in Mozilla Firefox on Post back
About Session or Cookies