Pass a variable to the signal hub r asp.net - webforms

0

I have developed a web application with signal r guiding me from this tutorial: link

It works fine, but in the tutorial the employee ID is not a variable, it is hardcoded in the hub class, I want to be able to pass the client id as a variable since the web application handles users. My question is, how to pass on the side of the javascript client or the server side aspx a value (code of the client that I get with cookies) to the hub class.

I tried using Context.QueryString ["userCode"]; but this works only the first time the hub is called, that is, when the application starts, when I make a change in the database and calls the hub again, the application falls down and says that the user code is null.

Thank you.

    
asked by Jeremy 08.11.2016 в 22:13
source

2 answers

1

Well finally I was able to solve this problem, maybe I will help someone else in the future. The solution was as simple as creating a static variable that stores the User Code, and in the OnConnected method of the Hub, I assign the value of the user code in this way:

 CodUsuario=Context.QueryString["CodUsuarioHub"].ToString();
    
answered by 09.11.2016 в 15:05
0

You can use session variables to keep the values and pass them between forms (it's easier) or use the observer pattern (it's more complicated).

If you choose to store values in the session variables, I recommend using another method to make a POST with AJAX from javascript to the form every so often and keep your web session alive.

I leave a link where there are examples of session variables.

On the other hand, I recommend you take advantage of this method to keep the session alive and update the DOM through webmethods, ajax and jquery.

Greetings.

I hope it serves you.

link

    
answered by 08.11.2016 в 23:01