Can somebody explain to me how the signalr/hub file works?
After reading through the documentation it says the file is generated at run time. However when i first load a site, you include it with all your other javascript files such as
<script src="Scripts/jquery-1.10.2.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.1.2.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
How does that work?
I can not find that file on disk at all, so how is the web browser able to request it like that?
Thanks for any explanations!
Like the documentation says, the JS is auto generated. The file itself won't be stored on the file system, but rather generated on request (probably cached) to the /signalr/hubs
location.
Type in http://myServer:port/signalr/hubs
into your browser and you'll see what the js file looks like.
The principle is the same as with every web application: the exact file you're seeing when you navigate to a page isn't a copy of some file from a file system, but rather it is the result of the server code running. Installing SignalR sets up a route to handle requests made to /signalr/hubs
and when requested will return the string that makes up the JS file.
This code is configured to run when you add the SignalR dlls to your project and prepare your server to use SignalR when you do the following statement, usually in Startup.cs
or whatever your Owin startup class is.
app.MapSignalR();
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
The Documentation explains that it a autogenerated file, that means this file actually does not exist in our project. Actually it is generated Runtime when a request is send to server.
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
});
});
});
when the above request is sent to server the further process of server can be seen in browser using below URL as mentioned in answer by #DLeh.
http://myServer:port/signalr/hubs
also can be observed in console panel.
For further Guidance you can use the following link.
https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With