✅ Help,web chat, i’m stuck
Hi, so i want to create a simple web chat(using mvc) , and i did, i wanted to make more progress and create users like login and stuff, btw i put sqlite as database so when i want to save the messages into the database i have to change this
And create context and stuff but when i run the application and want to send a message the message won’t send and gives me error in browser this:.error(err.toString());});
In my chat.js
Anyway here’s my git: https://github.com/Spaceismyhome/SignalRchatAppMCV
GitHub
GitHub - Spaceismyhome/SignalRchatAppMCV: this is from the Microsof...
this is from the Microsoft stuff, but it's under work, so i can make it a proper chat app, and for actual apps - Spaceismyhome/SignalRchatAppMCV
112 Replies
Add "anything" like... what
There's no way that adding
var i = 2 + 2
would break anything, for exampleCheck connection strings, make sure these are correct. Are you awaiting the send message method also
Would be useful uploading the repo so folk can check more thoroughly
Like private readonly AppDbContext _context;
public ChatHub(AppDbContext context)
{
_context = context;
}
public async Task SendMessage(string user, string message)
{
_context.Messages.Add(new ChatMessage { User = user, Message = message, Timestamp = DateTime.UtcNow }); await _context.SaveChangesAsync();
await Clients.All.SendAsync("ReceiveMessage", user, message); } But I can’t send the message when i click send after I debug the app? (When it works) I didn’t upload it to my git yet but when i do i will edit my post thx for the note.
_context.Messages.Add(new ChatMessage { User = user, Message = message, Timestamp = DateTime.UtcNow }); await _context.SaveChangesAsync();
await Clients.All.SendAsync("ReceiveMessage", user, message); } But I can’t send the message when i click send after I debug the app? (When it works) I didn’t upload it to my git yet but when i do i will edit my post thx for the note.
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/And what exactly happens when you add this bit of code?
I debug the the app so that i go to https localhost to try if i can send messages, but when i put messages in the box with the id, and i click the button send it won’t send it
Does the message get added to the database?
Also, what is
Clients.All.SendAsync()
?So that you can send the message to all clients (users) in one big room
Right, yeah, but what does it use, how does it work?
I just try sqlite so I don’t know how to check it tbh
Is it a static class that holds some websocket connection? A SignalR client you're keeping in a property?
SignalR
Did you follow the docs?
https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-9.0&tabs=visual-studio#create-a-signalr-hub
Seems your
SendMessage()
method should be in a SignalR hubYes.
Step through the code and see if at least
await Clients.All.SendAsync("ReceiveMessage", user, message);
gets invokedIt’s invoked in in wwwroot in js chat.js
Sorry my code is messy i was searching for it
Step through the C# code and see if the forementioned method call is hit, or if maybe the database saving throws an exception or whatever
What do you mean? Btw the database is sqlite, and I don’t have so many experience with it, i just used EF CORE sqlite and connect a controller with it so that it can make a database, but I don’t know how to check it if the data is saved
You can make a controller that will query this data, for example. Or use the SQLite CLI to query the database file
As for what I mean, I mean create a breakpoint inside of this method, run the code in debug mode, step through the code line by line, and see if you maybe get an exception somewhere or something
From what you're saying, the method is behaving as if
await Clients.All.SendAsync("ReceiveMessage", user, message);
is never called
Well, let's check if it is actually calledI will check and i will get back later thanks for your help man, appreciate it, i got some docs too to lock at so to know where I did wrong, i have to sleep right now, but if i got stuck i will send a message, thanks again.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Hi, so did inspect the browser and it gives me this

And apparently it doesn’t save anything in the DB, I’ve downloaded DB browser (sqlite) app to check it
console.error()
returns a void
, you shouldn't return
it
In any case, what does it print to the console?How so? You mean after debug? It won’t send the message

console.error()
prints something to the browser console
What does it print to console?There’s no console, I don’t really know, i mean, what console? Sorry but I don’t know really I don’t where to find that?


Right, so the error happened somewhere in this
SendMessage()
method
Check the server logs and see if they mention any exceptions
ive only found this tbh
this my git: https://github.com/Spaceismyhome/SignalRchatAppMCV
GitHub
GitHub - Spaceismyhome/SignalRchatAppMCV: this is from the Microsof...
this is from the Microsoft stuff, but it's under work, so i can make it a proper chat app, and for actual apps - Spaceismyhome/SignalRchatAppMCV
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Tbh I don’t know how to do that but thx, also i am really tired with this shit so i’m gonna just delete the whole thing, it’s not like i did a great change i can re-do it in minutes maybe then it will be better
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
You mean i might’ve installed wrong ver of EF?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Yea, I figured 😓🤣
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
…👍 tbh most of it flew over my head but when i redo my project i will come here to take a better look, thx for the notes though. I mean I don’t have really a good experience I’ve learn all by myself but I might’ve skipped some stuff I didn’t know
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
No, i was trying to do the database and then use them
Like for example when i sent a message to be saved into the database and stuff then take care of the login and chatroom stuff
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Serious answer:what is that?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Honestly i think it was just there
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I searched any there was mvc they said that good for chat app, and the Microsoft doc use that
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I had some exp with creating web api but I didn’t think about it that way for creating chat app
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Yep, i just wanted to create a simple chat app, so that i can be more experienced and went down to the rabbit hole
Yea, I’ve learned alot of html and css
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
So what should i use? Man i need it i mean it was for fun project, now it’s my graduation project 😭😭
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Oh, like 4-5 months
But i want to do it quick cuz i do it alone my colleagues don’t know shit and it’s mandatory to have partners
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
That’s it? Html,razor and blazor?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Tbh, i heard that signalr is easier, and I don’t have so much experience with servers, i hate that server stuff tbh(and network related)
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I mean i suck at it, I really don’t know what I’ve been doing at all, so that’s why i was searching
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Ah, yes, i knew it, that’s why i will just delete it and begin anew its much easier and I didn’t get that far
Btw , do i need just pick razor in creating new projects? In the .net? And do the stuff like ef and signalr and db? Instead of mvc or just use web API?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Razor Pages has been working well for me, well above 5 pages ¯\_(ツ)_/¯
Well, i need to create chat groups and private one to one chats too, so api it is?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I have no idea about razor so i need to watch a tutorial to learn the basics tbh
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Need to learn that too😭
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Can’t i use html and css for it?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
It’s easy for html and css for me at least, but i need functionality right now instead of ui so I would make bare minimum and when the app works well then i will consider make it beautiful
The JS code in the repo uses
function (){}
for lambdas, I'd say the answer is noNot really as i said i’m totally beginner if you like to say just watch my git it’s all my projects
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I don’t know what to say at this point 😂😓
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
As i said just do the project all over again, it’s much easier , so i use web api, and bare html and then razor that’s it?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Most of it was Bootstrap, from what I've seen lmao
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
?
Atp I don’t even know what you guys are talking about.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Yea i just found out, appreciate it, but the reason why I asked was cuz i want to do it myself, if someone did fix the problem for me I wouldn’t learn.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Right, so we still didn't really figure out what the issue was?
😂😂😂😂😂, he did, it’s up there he fixed it, but I don’t get it.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Ah
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
TeBeCo
Quoted by
<@689473681302224947> from #Help,web chat, i’m stuck (click here)

React with ❌ to remove this embed.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
🤷😓, don’t make your self more tired man, i will just re do the project with web API and stuff i will figure it out.also I merged the repo request in git you sent thx btw
I wouldn't be using a plain API project for this tbh, if for the ease of use alone
It's easier to have an
Index.cshtml
razor page or whatever where you can dump your HTML, and an API on the side
Than trying to return html from a bare APIUnknown User•2w ago
Message Not Public
Sign In & Join Server To View
Yea, i meant, web api,html, razor
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Yea, it’s as i had in my mind, like i’m not that stupid to try to put all the code in one place😂
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I might, and didn’t notice but thanks that helped alot tbh
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
No, problem, i’m not home now that’s why, and I don’t use discord on my laptop a lot tbh😂
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View