From the course: Building Real-Time Web Apps with SignalR 2
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Adding authentication to Fun Chat
From the course: Building Real-Time Web Apps with SignalR 2
Adding authentication to Fun Chat
- [Instructor] In this video we're going to be using ASP.NET authentication with SignalR to add usernames to our messsages, so we know who is sending messages. We'll start by modifying our chat hub, our new message broadcast to send out the username of the user who sent the message. We'll grab our username from Context.User.Identity.Name, and we'll pass in the username as the first parameter to our broadcast. That's the hub side taken care of, now let's just reflect that change on the client side. We'll go to our Index.cshtml. We'll scroll down to our onNewMessage broadcast listener, and add our new username parameter. We'll perpend our username to our message. And it's worth noting that the username can be null if someone is unauthenticated. So we'll handle that situation by saying anonymous. And let's run our app and see if that works. I've opened the app again in two different windows to simulate two different users. On the left side I'm logged in as a demo user, and on the right…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.