ASP.NET Core SignalR in the nutshell | Fiodar Sazanavets | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

ASP.NET Core SignalR in the nutshell

teacher avatar Fiodar Sazanavets

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

15 Lessons (1h 24m)
    • 1. 1 - Introduction

    • 2. 2 - set up your environment

    • 3. 3 - SignalR hub overview

    • 4. 4 - SignalR hub continued

    • 5. 5 - Strongly typed hub

    • 6. 6 - JavaScript client

    • 7. 7 - .NET client

    • 8. 8 - WebSocket client

    • 9. 9 - CORS policies

    • 10. 10 - User authentication

    • 11. 11 - Redis backplain

    • 12. 12 Azure SignalR Service

    • 13. 13 - IHubContext explained

    • 14. 14 - Azure SignalR REST API

    • 15. 15 - SignalR streaming

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Are you a web developer? If so, you would know that many web development projects these days require the ability to establish a persistent connection between a client and a server without having to keep sending repeated requests from the client. As you may also know, such functionality may be hard to implement.

However, if you can build your web application in ASP.NET Core, there is a way to make this whole process easy. There is a library called SignalR. This is what I’m going to talk about in this course. As well as doing all the heavy lifting for you, the library abstracts away all complex implementation details, so your code can be made extremely simple.

However, as you would already know, nothing in programming is simple in absolute terms. Programming is a complex activity, so even those concepts that are relatively simple require some practice and studying.

This is why I’ve created this course. By the end of it, you should be able to build a web application that clients will be able to establish a persistent connection with and exchange the data with in real time.

Before you embark on this course, you should already be familiar with full stack web application development by using ASP.NET Core.

Meet Your Teacher

Senior software developer specializing in .NET with several years of experience

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. 1 - Introduction: are your Web developer. If so, you would know that many Web development projects that these days require their ability to establish a persistent connection between the client and the server without having to keep sending repeated requests from the client. As you may also know such functionality, maybe hard to implement. However, if you can build your Web applications in SP that net core, there's a way to make this whole process easier. There's a library called Signal Our. This is what I'm going to talk about in this course. But first, let me introduce myself. My name is showed us is under that's and I'm a senior software developer, mainly working with dot net. Throughout my career, I have worked in a number of different industries, and there wasn't a single one of them where persistent real time communication between the client and the server wasn't useful. I have your signal I in my own work a lot, and they could not recommend it enough as well as doing all the heavy lifting for you. The Library of Struck's away all complex implementation details. So you're cold. Comfort made extremely simple, however, as you would only know nothing in programming is simple. In absolute terms, programming is a complex acidity, so even those concepts that are relatively simple requires some practice and studying. This is why I created this course, but the end of it you should be able to build a Web application that clients will be able to establish a persistent connection with on exchange the data with in real time. 2. 2 - set up your environment: before. I will teach you about sp dot net core signal out. I will need to show how to set your environment up so you can follow the lessons effectively. If you are using visual studio, I d. You click on file, create new project Select SP that Net core Web application as your project template. I'm alcohol. My project learning signal are I will choose version 2.2 off dot net core. However, most of the material I will tissue and electricity will be equally applicable in dot net call three. I just want applications. My template and I switch off configure for HCPs because we will only be using local build so we don't need any secure socket layer on a click. OK, if you don't use visual studio i d. You can likewise create a speed of net core Web application by using command line if you have dot net as decay installed. Likewise, if you use an operating system that doesn't have visual studio I D available, you can use ah cross platform called editor, known as visual studio cold. However, it will be much easier to follow this tutorial if you are using visual studio. All of the lectures are filmed using Visual Studio 2017. However, if you're using Visual Studio 2019 all of the material will be equally applicable to that. The only difference you will notice is that using interface looks slightly different. 3. 3 - SignalR hub overview: the service side, Components of signal are come together with SP that net core application by default by default SP did not score is referenced as Microsoft dot a speed of net cord got up, which essentially contains all the packages that I included in SPD. Net core one of such packages. This signal are, however, SP did not score up. It's probably nothing you could package she should be using in production. As you look at this list, least know that every single one of these references can be referenced separately as a separate Newgate package from Newgate Package manager. So if you are to use signal in real life scenario, all you will have to references signal our package or any other packages that I required in the application. For example, if you want to use NBC controllers, it's a reference and receive packages as well, however, to enable signal out in your application reference. In particular, you get packages is not enough. You will also need to register them by your start up close. The first thing that you'll need to do is at this line over here you only took out signal out to your services collection. Afterwards, you need to register the hub in configure method of your start up close. You need to add you single with the past year hub on with the actual class that you're using as your signal er hub Signal. A hub is the most central component off your service side signal are set up. It is a clause that extends hop based class in here. You can specify any methods that you will want your client applications to be able to call inside of this methods. You can create calls to your client applications of the moment. I have two methods on both of them will accept requests from any client applications. Aunt will send the same request to every single client application that is currently connected. As you can see, it sends the message to old clients. Sending a message to all available listeners is known as broadcast. This is why we called both of this month broadcast. In this case, we're accepting just a string message, just a textural value, which we are recent into a client. If a signal like line has received message methods, it will receive this message as a parameter broadcast object works exactly the same way. But instead of having a textual value, it processes the Jason object, which in C Sharp is represented by a C sharp class. In transfer, However, it will be represented as a Jason of the principle is the same. If a client has received objects methods, this method will be called with Labelled Variable as its parameters. Let's examine how based close in more detail. They're several fields That hub is this. So clients is one of the field that we already have a look at in your direct hub class. You can specify whether a particular message will descend to all clients in a specific client, and so forth Context Field is of type help Call the context object on. It provides information about a particular caller. Essentially every individual connection from a client's to your signal out. Seven has its own context, which will be identified by its unique connection. I d. However, as well as having the connection i d. It has some other fields that will be able to identify a particular user that is connected . We will talk about to use a specific connections later. There's also a concept of groups. Essentially, you can opt several connections on several clients, so particular group on pretty much anything you can do with clients you can do with groups . You can send messages to all the groups. You can send messages to all clients in a particular group and so forth. In late elections, we will walk you through a groups logic in signal out. And, of course, there those two of rideable methods. You can execute a particular piece of logic whenever a particular client connects to your hub on the you can execute a particular piece of logic with a client disconnect. Because this connections sometimes happen with an era. This connection event also takes exception as a parameter that is pretty much a basic overview off a signal of hub, a place where all of your service side logic will reside. Please note, however, that you don't necessarily have to have a single hub in here were just registering one of them, but likewise, you could have another class that extends have based glass. I'm considerate in exactly the same way as you've done it here just by I didn't corporal of this statement with a different class name and with a different path underneath this one, Just like with NBC controllers, if you're familiar with them, you can create several context, specific hubs. 4. 4 - SignalR hub continued: In our previous example, we have just provided a basic overview off a signal hub. Here. We have expanded on these concepts and have added some more detailed methods, so you can see various scenarios all the signal hub being used, for example. Previously, we could only broadcast a particular message to all connected clients. Now we have added several methods that send messages to specific glance. In this case, for example, we're sending the message back to the client that has originally sent the message. This client is being a caller off this method. This is why we're saying Cola. This method here works in exactly the opposite way. We're sending the message to all other connected clients, but not the client that sent the message to start with. This is why we're saying others in this context. Now here's an example of group. Instead of sending a message to a particular client, we're sending a message to all clients in a particular group. This method, except the group name is a parameter otherwise in all of this month is the logic is exactly the same on the client side. We're calling exactly the same method on the client side. The only thing that is different is which clients will receive the message, but we're signal on with us. It doesn't necessarily have to be the case that we're just re sending the message to particular clients whenever we receive it by one of our have methods. For example, in this case here, we can add ourselves to a particular group by specifying its name. We are identifying ourselves by this. The context will indicate the connection that Haas coldest methods. So in this case, well, we're calling groups at the group. We're adding our own connection to a particular group with a particular name, and then we are notifying all the other users. That particular connection has been added to a particular group while we're sending a different message to ourselves. Likewise, we can remove ourselves from a particular group. This Memphis here are identical to the ones above, apart from the fact that they received the payload object rather than a string message armed. Likewise, very calling receive object rather than received message method on the client side. Here's an example off our events on connection on on disconnection. As you can see here, every single connection is added to have uses group whenever it connects. Likewise, when client disconnection, because it's the connection I d gets removed from have uses group. So if you are Colon sent a group message with HOB users specified as the group, it's essentially the same as broadcasting the message to all uses. Every single connected user will receive the message. 5. 5 - Strongly typed hub: In our previous examples, we have seen messages being sent to clients via magic string. Essentially, the method on the client side was denoted by a string value either received message all received object which is not ideal. To be honest. Of course, string can be stored in the constant variable, which is one way of doing it. So if you create a new method on a signal hub that uses the same method on the client side , there will be less chance that you will miss both the method name, essentially with signal I. If you specify the client method that client doesn't have, nothing will happen with the client that doesn't have that method will not receive anything . However, a better way of doing it in signal are is to use a client interface way. You can strongly type a method signatures off my thoughts on the client side, and this is what we've done here. So the client interface could be absolutely anything is just any standard C sharp interface . But when we are creating our strongly typed hub, we're using inheritances in a slightly different way. Essentially, what we're inheriting from generic version off the hub we don't have sent a think method available to us anymore. Instead, we have the methods that have been specified by our interface. So now this cold looks as if we are directly Colin methods own Al Cline's as if our clients had just founded C sharp glasses. Of course, this is not how it was behind the scene, but it is a very convenient way off program and things in signal. Our this is the main benefit of signal are it allows you to obstruct away all the complex implementation details. So defining your communication logic between clients on the service will be just a simple US defining communication logic between C sharp glasses in the same section of application . 6. 6 - JavaScript client: jealous kids Glance with signal comes off mpm package something. Install it You would need Teoh. Initiate it as if you are initiating no Js application. You can either use command line or, uh, package manager council from visual studio. If that's the I d you're using in this example here will be using package manager. So the first thing that young is the type is and PM and still this will add all the necessary files to your project folder. After that, we need to initialize our project to do so. We type and p m. And it's Onda. We put the wife of flag s so we don't have to be prompted for confirmation. This has created this file, Dr Jason. Now we need to add the actual library for our JavaScript client for signal our So the command is and PM install followed by an explosive package name. I'm the Turkish name that when it installed is at SB ESPN dot net. I'm single. As you can see here, there's the six packages have been added. Let's have a look of them. So the last command that we have executed has created node modules folder inside of our projects Folder on all of these are dependencies off our signal package. What we need to do is to go into a speedboat, not signal a folder going to dist. Which starts for distribution. This is essentially before the where you store compiled JavaScript files that you can inject into your own application. That's just a no jest terminology. We're going to browser folder, and then we need to call police to files regalado gs on signal. I don't mean the GS going back into our solution folder. We need to open the folder for our main project, expand www route, locate Leap folder and create a separate folder for Signal Our. And this is where our gentle script files will go. If we're going to our layout page, we have also to set it up. But to use singular whenever we're using development environment, where I just using full signal Our version, I mean production, environment, ways and modified version. Essentially, the difference between the versions is as follows does the full version. You can really, quite easily. The variables are well, types. Even though he's big, it is easy to follow notified version. On the other hand, is really compressed, so it's not very easy to follow it all. As you can see, all the statements are just ah, compressed into a single line. Always places a removed, likewise variable names and shortened, sometimes even to a single letter characters. I mean, if I just could files take a lot less space. This is why they are usually used in production, even though those are difficult to debug. Production is not in the environment where you would normally debug. You're jealous. Creep on de bargain is the reason why he was still used. I'm compressed. Original version in development environment. Let's now examine our index page. So for every action that we have in our signal hub on the server, we have a couple of text boxes and buttons to be able to call that method. Our index page is a HTML that enables us to do it, but our side Js file is a file with the actual logic, because we have specified reference to our signal largest file before we have specified inside dot Js and isn't that we specify here come to reference from side Yes, and this is how we are establishing signal our connection. We're already referencing this signal on library on every single page because layout is shared between all of our pages. Here we have two event handlers, one for received message, and the other one is for received object. If you remember those, those are the methods that were calling from our signal on the server. And after we connected our signal hub. These other event handlers that will receive the calls from a signal have itself. I wasn't that were just associating various actions with the elements in our index page. So, for example, we never press beauty and broadcast bottom. It will involve broadcast message method in signal a hub. So this matters here will be called and so on and so forth. We do essentially have a button on the a bunch of text boxes for every single action that we have, you know, a signal, a hub. Let's lunch hour application and see how it works. So if I want to broadcast the message, every single client will receive it myself included. I can do the same with the object objects. It will be adjacent object that will be done, uncle created by JavaScript as soon as I presidents bottom, the fields off the object will be populated from the values in this fields. Here, aunt, as you can see here, it's a Jason, but it's handled by Singler Hub. If I put a break point in Signal Hub, I'm broadcast the message again. As you can see, we're getting this Ah, break point just to prove that it's actually signal Hub on the server that processes this logic. And it's not just JavaScript itself that it's populating this panel here. I can send a message to sit to myself if I sent to others. If you remember, this particular action references other clients, but not myself. And this is why I, as a client, don't receive this message anymore. We can send a message to a particular group. If you remember, every single user gets other to hub uses. Therefore, if this works correctly, I should be able to receive the message, and I do. If I however, send it some group that doesn't exist unless that happens, On the other hand, I can always out myself to a particular group on. If I send the same message now, I do receive it because I am now member of this particular group have used it one. Once I remove myself from this group, I'm trying to send the message again. I don't receive it anymore, that essentially what it is in a nutshell, We do have every action for sending message, Aunt sending object. And this concludes our lesson on the basics off how JavaScript signal our client works. This kind of client is probably the type of client you will be using the most in your signal on applications in real life. Although you know the next lesson, we will cover the next client, which in my practice I have used quite a lot as well. 7. 7 - .NET client: we have added this basic consul application as our .net signal like line in here. Our entire logic resides in just a single program file. However, in real life scenario, you would probably split it up between multiple files to properly apply a single responsibility principle. Would you have a message Payloads class, which is pretty much identical to message payload class from elsewhere, the one that we have on our service side. The reason why we are duplicating it is because in real life scenario signal, our client will probably have no reference to signal our server application. Therefore, we need some kind of class that has exactly the same structure as the one on the server. Well, it doesn't have to be exactly the same one on our JavaScript clients. We have just shown of a very basic example in here. However, we're adding some more complexity to it. One of the things that we are did here is their ability to set up your transport mechanism by the fault signal. Our connection will always try to use a web socket. Web circuits is a standard protocol for two way real time communication between the client and the server, and this is the best transport mechanism that signal Arkan years. However, not all the environments enable Web circuits therefore, signal level four box of service ENT events. If it cannot use Web circuits or if it cannot use seven cent events, it will fall back to long Poland, which is essentially just to send in the http request. I'm done waiting for the response to come back as soon as the responses received were sent in another http request. So we will be resending along point requests until the application stops, which will work on pretty much any environment. But it's not as efficient as the Web circuits or service and events. But one thing you can do with single like line is specify your on transport mechanism. I'm not. Let's a signal I've decided for you and this is what we've added to our council based application. Although you can do the same on JavaScript declined just as before. We're using builder class and we have two ways of initiating our heart connection. We can just specify the Ural, in which case the system will decide for us what transpired mechanism to use all we can explicitly specify transport mechanism. In this particular case, it will be based on the user input, which have a number the usable choose. Here we have our event handler, just like we have in our job script application. Those are just simple methods. As long as they much particular signature on the particular parameter data type, Any message will do. I'm here. We're basically just interruption with the application. The application prompts us to take a specific action. We can just keep taking this action until we get bored of it. I would type exit to exit the program. In the meantime, while we're doing that, any message that is received from elsewhere from another connection will be outfitted into our council application. As you can see here, whatever which is some action, one type of message, it will call a particular message on the signal hub to see both of them in action. It will be convenient to choose both of our projects as a startup project uncertain. Both of these projects are start up projects will enable us to launch both applications from the same visual studio session. So just so, we're actually going solution and quicken properties. Those select multiple startup projects. Don't we just choose them both to start? I'm not on this largely application. Once I was set aside, application is launched. We will use the same, you know, in our .net client application. So the euro will be the base. Your role of the host followed by the hub name. The hub name, if you remember, is what we're specified in. Ah, your signal. Our method. It starts up close, you know, case I'll just choose default. Transport mechanism on the connection has been successfully established. So if I now broadcast message to all connected clients I received myself. Aunt. As you can see here, this application has received two. Likewise. If I received the object, it gets serialized into text. If I sent a message to myself I received on this side. I know this is nothing on this side. If I send message to others, I don't receive it myself. But the other clients receives it. Likewise. I can just broadcast the messages from this application A z can see here the other client receives it. Aunt, you can do the same with the other Memphis as well as they are listed here and this concludes our lesson about don't not signal a client. In our next lesson, we will cover a little bit of other non standard scenario the one, however, that I have used in real life situation in my own career. We will look at how to set up a plane left circuit gland. I was a signal lock lined that might be a requirement on your project to build a Web socket client. It will be universal. That wouldn't care whether the service side of it is another Web circuit. All signal. Er, because signal does work with Web suckers, you will be able to connect to such a cup circuit gland to signal our 8. 8 - WebSocket client: For example, we're just using standard oh clientele of circuit, which is part off system library. I'll face because not score this application works differently from our standards. Signal our client on with this example You will appreciate, um, how easy signal lawmakers to establish it up circuits protocol in this plane Web sockets. Client of the implementation complexity is not hidden. You will have to deal with the champ bite a race to transport messages between clients and the service. So the first thing I would do here you specify the Ural just like we've done before. The only difference is that we use AWS protocol rather than Mississippi with signal our client you just use standard. You're also you don't have to be confused which protocal to use in which situation and it does political conversion To have this scene with Web circuits client, however, you have to specify who have circuits protocol explicitly. Once we specified the euro, we need to send this handshake request. This is what ah signal our client does behind the scene and this is what we are mimicking in our website. It's glad so our website it client will still be compatible with our signal hub on the server. We're just providing some basic example, so we don't have any actions in this particular example off our school and methods on the server. However, we have this matter to receive any data from Austin Lock lines because the data comes as bite a race. We don't really care about the data type on we can convert any of this data into textual equivalent with Web stock is that the data is not really received in chunks. And this is how we're doing it here because we're receiving bite of race. We need to decode them. You know, Dick old methods. We are getting rid off empty bites of the end of their way so we don't get some undesirable characters in output. And once we've done that, were just converged on everything is the string on. Just after eating it in the council, I'll now set up a website its client to be one of the stars are projects, and we'll see the whole thing in action. So once I was satisfied, application is up. We can specify the your altitude, but remember, we need to change the Protocol two ws or if our original protocol waas haste it. Yes, this equivalent would be W s s. The second s stands for secure as before, we're answering our signal hub. Bub, please know that we're not filter in any particular data. What we're seeing here is just a standard hardly to request data gets transferred between client and the server all the time to make sure that the connection still works. Now, this is what we're seeing here. If we are to use the web socket client in real life, though with probably filter those out. So if I now broadcast message to all the clients I received this Based on this object, you can probably figure out the structure off a singular calling partner, essentially behind the scene, taking on a message just gets transferred as a Jason file on one of the promises of that file is the method name on the client. The other parameter is arguments which, in our case, is just a string message. We could actually build our website, his client, so it's much more similar to a standard signal like Ryan. But then again, why reinvent the bicycle if we already have a standard way of sending signal our client messages. If I send object, as you can see here, received object is a target method on the argument is the Jason object that we sent send into self and send it to others works in exactly the same way as before. There are many ways off using Web circuits in C sharp and dot net, and this is just one of them. However, if you do use this Parton, if you do, for example, some of this hunt check requests and so on, you can use absolutely any looks like it library to build a signal. Our client. But then again, this whole thing with on the apply to applications that are gonna stick off signal are being present on the server or not. Much preferred way is just to use signal our libraries on the quiet out on the server. 9. 9 - CORS policies: before we go into use a specific security, such as authentication on authorization, we'll go through the course, which stands for across origin results. Sharing This is something in SP dot net core in any other types of replication that will allow you to either restrict alone requests your application from other domains. So essentially, even before you configure any authentication authorization, you can just bun a specific domain from assets in the application altogether. For example, a particular domain or I P address might be registered on spammers database. It might belong to known spammers. Therefore, you don't want them to contact the application in any way. In another scenario, you might just allow anybody so access. The application, as long as they are, is indicated and authorized. They're also scenarios where you want to apply and makes shoulder to. For example, you may allow get requests to come from anywhere, while any other types of for http requests should only come from authorized domains. Let's have a look at how it's done in sp dot net score so, you know starts up close, which you should recognize as the class where most of the application configuration happens when our application is launched, we are. Didn't this method to configure services method in here? We are ardent to course policies. First policy we're calling, allow any get and in here we're configuring Any get requests to be allowed? Doesn't matter Whether you come from below is an example off another course policy we called it allow example domain. In this case, as long as our requests come from example dot com any cases it method is allowed, regardless of whether is get post put, delete head and so on until apply all policies. We're making these calls inside of our configure method inside of our pipeline. In this case, we're just changing them. So in the first call to use coarse, we are referring to our allow any get policy of them. We use in another call to use coarse with allow example domain and you can specify as many policies as you want and it's up to you how many of them you actually use. So if I would do this, for example, I would not be using allow any get policy anymore. I would only be using allow example domain. Please know that the things in configure method have specific order. So if you want to apply your course policies to both NBC and Signal ER, you have to specify this before you specify use signal are on the usembassy. The same applies for any other security filters. You have to specify your filter before you specify configuration of your hub and that covers our use off course policies. In the next lecture, we will have a look at how to use use a specific security such as authorization and authentication. 10. 10 - User authentication: In this lecture, we will cover user authentication and authorization. Andi. I will also show you how to send messages to specific users. Sp dot net Core has inbuilt mechanism for user authentication and authorization on it's known as SPD. Net core identity just like with the our signal, our library. Ah, identity Newgate packages included in the main espirit de corps up. However, in production environment, you probably don't want to reference the entire up. It's a lot better to reference new get packages in the module of fashion, so you will only reference the ones that you need. Otherwise, the application would be way too big. We don't have reference to a spate of net core identity. We can then configure the pipeline. We have other this block of cold here. This is identity options, which will tell us what's kind of users allowed to be registered on what other options apply to registered users. Once a particular user has looked in, a cookie is created. This is how we configure Cokie authentication options. And of course, we need to have this user authentication call to our pipeline once again. Isn't education needs to be added before your signal and use NBC if we want to actually apply our authentication in either signal our hub or embassy controllers, all anyone else on all pages. So cold wife were set up already. However, we need some kind of bug and database to store our users on the easiest way to do it in the SP that night Complication is to Scott. Fold it once again in production environment. That's probably gonna be a separate script for creating the user database. Or maybe you will even be referencing some third party authentication providers. But for the purpose of our lecture will scuffle the database, so we will have our user information stored in our local SQL database. To do so, we likely can Our project we can add Click on Scuffled item as a nice inside, which is identity. We will apply. Ah ah. I speak little score identities to everything. So we will modify all the files. We will create new pages. However, in this process, you can just choose to do it in a module away. Just modify the pressures that you want to modify. Perhaps you won't need to modify. There are the pages. Oh, maybe you will choose to do so. Monument by applying some non standard configuration in here, we choose our main layout page, which will be in our Pages Shares folder and as a data context class, we just create one Conforti int process will create all the missing pages that we need for a speedy net core identity. The process may take a while once the process is completed. I read me file able to create with the further instruction. What we need to do now is run migration scripts to create the databases, and there are two ways of doing that. If you are outside of visual studio, I d. You can execute these dotnet commands, However, as we are already inside of visual studio I D. It's much better to use a package manager, so we go to package manager council only copy and paste script number one. Once this action has completed, we can execute the second action. In my case, it has shown another because I already have local database with the SPD net roles. However, if you're starting from scratch, you will need to execute sleep number two. So let's open our heart and see what options we attitude, as you can see here, broadcast object on broadcast message. Both have authorized attributes on them. That means that on the authenticated users can execute these actions, so you have to be looked in. To execute any of these actions, however, is just a plain authorized attribute. It doesn't have any further restrictions on it, which means that absolutely any authenticated user can use this actions, any actions that don't have a tribute I still accessible by any users, regardless of whether they are authenticated or not. I can, however, put this attribute on top of the class itself, which will mean that by default, every single action of this class will be on the excusable but authenticated user. If I choose to do that, I can put ah Lohan. Animals attribute on any action that I still want to, um, make available to any users, regardless of whether they are authenticated or not. But in our case, let's leave it like that. So only broadcast actions will be restricted to authenticated users are the uses to group on remove user from group examples of the action where we are restricting the usage by rolls. There are several other things that you can restrict things by. So, for example, you can restricted by policy you can restricted by authentication schemes and so on. But in our case, we're only given access to these actions to those who uses that are registered as Adnan. So any user that is added to admin role we'll be able to execute these actions otherwise, even if use the use authenticated. If particularly using is not inordinate role. Those actions will not be accessible. Please know that this actually is are not specific to signal our the same attributes can be applied to embassy control. This as well. Another thing that we added to our hub is the ability to send message to individual users. So we have out it sent to user on sent object to user. The way we're identifying the users is the simplest way. That signal that allows it to do essentially what we're doing here is just creating a single user group, so as long as uses authenticated ah, particular connection ideas registered in the group with the same name as they use the name . This will allow for the same user to use several connections. For example, If I opened the application user interface, why desktop PC and authenticated into the application. Then I opened the same application via my mobile device and authenticated inside. Both of these connections will be added to the same group with my user name. Unlike wise, every time I disconnect any of my instances, the instance with this particular connection idea gets removed from my user group. Now we will launch our application to see it in action. But before we do so, we need to make sure that our Logan link is available on our layout. So we'll go to the section that identifies our number, but our navigational. But and as you can see at the moment, looking link is not available. Logan partial is a page that has been added by our scaffolding process, but we don't come. We have any links to it in our layout page. So we just added, here and now we'll launch our application. That's our Logan partial So looking register new user. We can log in as a user if I try to broadcast the message now because I haven't logged in yet. Nothing happens, however, if I send message to myself which is an action that doesn't have authorized attribute. I can just still do it. I'll register as a new user and authenticate this action has automatically loved me and as well. So if I try to broadcast the message again, the message can't be broadcasted and as well as this because the back and knows the user name. This application is more like chat. Now it tells me which user has sent the message. Same applies. If I tried to send a message to myself, however, please know that there wasn't any adamant field or that there wasn't any role selection field when I registered this user. So by the fold, the user that are registered now is not another man. Therefore, I should not be able to add myself to a group. So I've just attempted to add myself to a group called Hobby User, too. If I now try to send the message to this group, nothing happens because I, as a user hounded added to that group. However, if I send a message to myself, I can just so because whenever I connected to signal a hub have identified me and it added my connection, Teoh group with the same name as my user name. If I change something in the user name and trying to send a message again, nothing happens because the message was attempted to be delivered to another user with this name. If I now look myself out, tries to broadcast message once again, nothing happens. I can still some message to myself, but because I'm not authenticated, the bucket doesn't know which use I am. Therefore, it doesn't prepared the text with the user name in front of it. And these were the most important fundamentals off how authentication and authorization work in a speed awareness course signal are. 11. 11 - Redis backplain: when your application, which is a particular size, you will have to start thinking about scaling it out. Because if you are just running one instance, there's obviously one point of failure. And also it might not be able to handle the amount of load. If you have so many users connecting to it every single day with signal er, there are too many ways off scaring application out. If you want to keep your application running on the premises, the way to do it is why I already. However, if you don't mind outsourcing some of the work to Microsoft Cloud, there's also a Jew already service. In this particular lecture, we will talk about readies read. This is ah, type of data storage that uses key value purse to store data. It can be used as a data storage, but likewise it can be used as a message broker in signal are it's used pretty much as bold . It's often referred to as readies cash because all the data is stored in memory. Once you switch the machine off, your data is gonna dippers, so it's not used as a persistent storage like, for example, Mongol or SQL databases. The official reddest website is readies dot io on by the false. It only comes for Lennox. However, there are several ways off making it. Install a bill on Windows as well with a Chester installers on Windows. So Lennox off which limits is recommended. Just make sure that the U R L to you already server is accessible by your application. In my example, I have chosen to install it on Windows, so I have just started Ready server, which will be accessible by Port 10,001. Once you configure readies connection string for your signal our hub. You may have as many instances of that, huh? Brunnen As long as they used the same connection string, there will be working as if it's the same application it doesn't muscle with. A particular persistent connection is made to a particular instance of the application running. Whenever you receive a call to send message to a particular user or particular group that is back plane. We'll know exactly where to send the message to. I'm the correct users on the correct groups will receive the message to enable Red it's in our application. We need to installing you get package of the new package is SP did not score signal a reddest which isn't installed by default. Unlike the main signal out package because red is back plane is designed as a Nadon. It has not been included into the main espirit de Corps package was the package has been installed Will need to modify this registration call. So we're ardent adventists. Two outs signal on As I'm running my instance locally I specify a little host is my address . Ondas you remember the poor that I'm using is 10,000 and one. If you're not hosted, Red is on the same machine as your sp dot net core application just used the I P address or the host name of that machine to simulate several instances of pockets running. We'll just copy our main project and it will keep the exactly same name, but we'll out to at the end Now if we go back to our solution, will just have this project doesn't exist in item before we can lunch. Both of this applications One important thing to consider is the port number, because we made an exact copy. No final project the port number by default will be identical if we just lunch hour application from visual studio. So whatever the port number is, we need to make sure that the other application uses a different one. So we just write quick on the application, Go to debug. I'm change the port number to any other value. Now we'll set both of the projects to be a start up projects. If we launch them, those projects will be acting as if they are two separate incidence of the same single application. So anything I do in one of them will be done on the 2nd 1 as well and vice versa. So here we go to identical pages in different Google chrome windows. If I look into one of them, I'll be able to broadcast the message to all connected clients. And as you can see, the other application has received the message. Now this is because they are using the same readies, but plain on exactly the same readies connection string. Likewise, if I send message to myself, this clan is the only climb that receives it, and if I send the message to others, the other application receives it. I still haven't looked in this application. But because I have a user connected to another application, I can use this application to send message to that specific user. And indeed, I do receive anonymous message that says, use a message that is sensible from other application. So this in that show is how you scale out Signal arm by using various back plane, which is the best way off scale in our signal life. You want to keep everything on premises. However, if you don't mind all source in scale and our capabilities to Microsoft Cloud as your signal, I is another way of doing it, which we will cover in our next lecture. 12. 12 Azure SignalR Service: in this election, we will cover houses. Scale out signal are by using azure portal as you a signal of service. If you haven't registered on Azure before, Microsoft actually offers free trial with some of your credit so you can sign up absolutely for free once the trial period expires, you can still use azure for free as long as you're not using any services. Basically, with azure you on the plane for what you use them. So that's where the obvious disadvantage of azure signal last service comes compared to read his back playing. If you are to use azure signal last service to scale your signal application out. You do have to pay it if you have a large user base of it. Once you've arrested in Azure, you can go to Azure Portal, which is available at portal dot azure That come uncle, we can create results as a resource type. Find that signal service. Once you're on the signal, all set up page. You can create new results group If you haven't got one already, give the results any name you want. Select geographic region that is the closest to you because this way the communication between cloud application on your own applications will be always faster. Choose free as the prices here. Unless, of course, he wants to use your results commercial afterwards when she probably wouldn't do in this case, because this one is purely a learning exercise. And then once you happy with all this options, you can just click, review and create. Once the application has been created, it will have its own certain space where you will be able to access its keys and connection strings to enable as you a signal I in your application you in this rods and you could package and then you get package is Microsoft 0.0 dot signal. Once they get package has been installed. We're changing this to add azure signal. On the other parameter, we're using whatever connection string you can find in your application. Obviously, service endpoint on access key will be your own service under point. I'm access key that are specific to your application. That's it. That's all you have to do. Unlike readies, you don't hunt should have to have multiple instances off the hub running, even if you have a single instance off the SPDR Medical host application with just one hard running. All the connections and all the hub logic will demolished by Cloud on Azure will scale it out itself as needed. So even though you do specify your application logic in the solution itself, the execution of this logic will diminish from the cloud off course. You may still want to have multiple instances off your application running because it's a speed of Nikko application. And, ah, you may want to be able to serve as many pages to as many users as possible if there, for example, access in every sea controllers. But scaling off signal I itself will be done by cloud on with as your cloud your pain for as much as you using. So while you don't have enough money, use is connected to the application. Microsoft will not charge you much if you do, however, have many uses connected to your application. It will be more expensive, but it doesn't matter how many users you have. The application will be elastic, and it will scale out automatically to meet the demand. Any real time communication between the sort of on the clients will not be slowed down 13. 13 - IHubContext explained: in this lesson, we will cover how to send messages to your help from inside of your application. On the service side, there are many reasons of why you might do it. For example, it could be a user action on one of your embassy controllers that needs to trigger particular logic in the hub or something else, you know. Example. Here, what we are doing is association. I will have with the log in page. So whenever any use of successful logs in any connected clients will receive information about it in signal out, this is achieved by I have context interface which gets result to, ah, concrete class because we have this action here, please know that we disabled as your signal out for now on. The reason for that is because I have context doesn't work with is your signal and also for demonstration purposes, which in our case don't currently involved visual signal out. So let's go back to our logon page. Have context. Come take either one type or two types. The first type should always basically hub, while the second type is optional and it can be interface if you are using strongly typed hub. If you're not using strongly typed hub, you can only use send a C and committed. Otherwise, you will be using the methods that are specified in the interface that you are using. So the object is inserted as a dependency. It will resolve to the correct one because we have registered it in our startup class. This is where we're using it. Whenever there's a successful log in, all the clients receive information about it. They will receive the message that particular user is logged in. Let's lunch hour application to see it in action for this particular scenario, we just need to use one startup glass. So we're just says in our main signal, our application as a starter project. We'll open another top, so we'll have to. Instances of application running on one of the tops will log in if we now open another tub . We see this message here. This client has been notified about successful logon attempt from another connected client 14. 14 - Azure SignalR REST API: have a context that we covered in. Our previous lecture allows you to send messages to the hub from any instance of the application. So even if you have a scaled out if you, for example, use the same readies back plane, any instance of your application will be able to send messages to any of the users connected to any other instance off your scaled application with as your signal our service . However, the process is different because as your signal our hub it's hosted elsewhere, you will need to use the rest AP I, too connected. The advantage of it, though, is that the calls don't need to happen from your own application. You can integrate it with the any third party application as well, as long as you've got credentials to connect said, and isn't come to connected to it. This is not the same ascended messages from the clients. The applications that use the rest, a p I liberal as adults to the server rather than help clients help clients, On the other hand, are entities that are connected to your hub by a persistent connection. They're several end points that are available, which we will cover. You know, reference material in our example will just show you one of them, the one that is used to broadcast message to all the users. This is the basic Ural structure of unit to use. Obviously you replace instance name with the name that you've given to your signal. Our service on the heart name is just the name of your hub, which in my case, is leading Hub. The rest of it, it just done as if you are sending any standard post request to any standard Haitian CP and point I have chosen to use his Chesapeake lined see shop class. However, you can use any close that house capability off center. Hey, she's API requests or if you are using and the other type off client, for example, JavaScript. You just used whatever equivalent is available there. Signal out message is adjacent file. Well, that will be the payload off the message that you sent into it. Logically, it's equivalent to what we've been doing before. As soon as any particular user logs in were sent in this request to signal last service on all clients that are connected to that particular hub will receive it brave old message has target on arguments. This is a structure that we're familiar with after we examined our website, his client. Now this is how it works in signal are started is the name of the method that will be called on the clients on arguments is an array of arguments because we have configured our clients to have a string parameter and received message method when I just using one value , which is the same as the one we've been using before user years. The name look then and here we're just creating the rest of the request. We need to specify that its application, Jason, because we will depose and Jason files. However, we can not just connect any random application to signal our service ready to use bearer token of education. And for that, we have created this help a class. You can examine the exact logic off how we creating the token. But this is what the parameters are. We are using our standards connection string, but we confined in azure portal. If we go to our settings page for the signal our service resource, we are using the hub. You are other. We specified above on. If we have to send a message to a specific user, we can also use user I D in here and once we're ready, we can just create a request and send a message. One advantage of this method over help, context or any other is that if message has not been successfully sent, we received a response straight away. While a standard signal are works in more fire and forget fashion, we have previously seen how we cannot send messages to specific endpoints on the heart because we haven't been authorized to do so. But we never actually received any prompt on the user's side. If you are using a sure signal service, you'll be able to receive the error messages as well. 15. 15 - SignalR streaming: we have already covered multiple scenarios. Well, we are sending messages between signal our clients on the server. However, as well a cent in individual messages. Signal light is also capable of streaming. For example, if you want to use it as a movie Sarah on audio server, you can still use signal off. For these purposes, going into fine details of how movie or their data is structured is beyond the scope of this particular lecture. However, signal that allows you to stream absolutely any data type. In order to be able to do so, you need to have a public, have my third, then returns Channel Reader. It is a generic data types, so you can specify any data type to be returned. So essentially your client will receive a channel connection and then via that channel, the data is gonna be streamed. We are relying on this private method here. It takes a writer off the channel that would have created on just populated a synchronously we are awaiting for anything to be completed. We're just sending channels to the client on the client will receive. All the dates are synchronously, so Allah have will still be usable by other clients. I'm the same client as well, While the data is being streamed to this particular client in our case, were taken counter on debate promises. So whatever we specifies a counter, we will populate every single one of this numbers starting from zero. And we will wait by the amount of nearly second specified in delay parameter even have receives an error. For example, A for client has closed the connection. We're terminating the writer. I'm likewise we're terminating the writer. I'm completing it when you have covered all the numbers specified in count parameter for our signal lock lines, we have added another option. We're just reason the same a c sharp glad we created before because stream reader is in a synchronised task. We have turned main method from void. So I think of a stauskas. Well, however, before you do so just make sure that ah, your current language supports it to be safe. Always specify a long version as the latest. Once we choose six as the option which is stream data were prompted to specify the counter on the delay parameters and then we just listening for the output from the server. Let's see this in action before we do so. Let's make sure that we are selecting our main espirit de corps application on our daughter client as a startup projects. We are also because we're using it in local context. Let's make sure that we're not connecting to your signal and we're not. Once on an application is launched. Let's just copy the euro specified default as a transport mechanism. Specify. Six Has the option. I'll specify. 10 was account on one second I 1000 never seconds as the wait interval. And as you can see every second, we'll get a new number and they get implemented until they reach 10. And once the rich tan, it's a streaming completed. This concludes our lecture on signal Last treatment.