Create a Signal R Hub OnConnected with startCalled











up vote
0
down vote

favorite












My C# method 'OnConnected()' in my Singal R hub class calls



Clients.All.setConnectionStatus(profileId, true);


with every page load and login!



With my 'OnDisconnected(bool stopCalled)', if there is a logout I check for 'stopCalled', which gets set to false with a logout and true for a page load. Is there anything I can do in the 'OnConnected' method to check the same thing? ex. 'bool startCalled' which just looks for a login and not a page load!



Because currently, with every page load, I have to send out a 'setConnectionStatus', which is seemingly redundant and an overkill.
Isn't there a way to just look for a login similarly with the 'OnDisconnected' ?



public override Task OnConnected()
{
string profileId = Context.User.Identity.Name;
_connections.Add(profileId, Context.ConnectionId);
Clients.All.setConnectionStatus(profileId, true);
return base.OnConnected();
}

public override Task OnDisconnected(bool stopCalled)
{
string profileId = Context.User.Identity.Name;
_connections.Remove(profileId, Context.ConnectionId);
if (stopCalled == false) // log off only
Clients.All.setConnectionStatus(profileId, false);
return base.OnDisconnected(stopCalled);
}









share|improve this question




























    up vote
    0
    down vote

    favorite












    My C# method 'OnConnected()' in my Singal R hub class calls



    Clients.All.setConnectionStatus(profileId, true);


    with every page load and login!



    With my 'OnDisconnected(bool stopCalled)', if there is a logout I check for 'stopCalled', which gets set to false with a logout and true for a page load. Is there anything I can do in the 'OnConnected' method to check the same thing? ex. 'bool startCalled' which just looks for a login and not a page load!



    Because currently, with every page load, I have to send out a 'setConnectionStatus', which is seemingly redundant and an overkill.
    Isn't there a way to just look for a login similarly with the 'OnDisconnected' ?



    public override Task OnConnected()
    {
    string profileId = Context.User.Identity.Name;
    _connections.Add(profileId, Context.ConnectionId);
    Clients.All.setConnectionStatus(profileId, true);
    return base.OnConnected();
    }

    public override Task OnDisconnected(bool stopCalled)
    {
    string profileId = Context.User.Identity.Name;
    _connections.Remove(profileId, Context.ConnectionId);
    if (stopCalled == false) // log off only
    Clients.All.setConnectionStatus(profileId, false);
    return base.OnDisconnected(stopCalled);
    }









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      My C# method 'OnConnected()' in my Singal R hub class calls



      Clients.All.setConnectionStatus(profileId, true);


      with every page load and login!



      With my 'OnDisconnected(bool stopCalled)', if there is a logout I check for 'stopCalled', which gets set to false with a logout and true for a page load. Is there anything I can do in the 'OnConnected' method to check the same thing? ex. 'bool startCalled' which just looks for a login and not a page load!



      Because currently, with every page load, I have to send out a 'setConnectionStatus', which is seemingly redundant and an overkill.
      Isn't there a way to just look for a login similarly with the 'OnDisconnected' ?



      public override Task OnConnected()
      {
      string profileId = Context.User.Identity.Name;
      _connections.Add(profileId, Context.ConnectionId);
      Clients.All.setConnectionStatus(profileId, true);
      return base.OnConnected();
      }

      public override Task OnDisconnected(bool stopCalled)
      {
      string profileId = Context.User.Identity.Name;
      _connections.Remove(profileId, Context.ConnectionId);
      if (stopCalled == false) // log off only
      Clients.All.setConnectionStatus(profileId, false);
      return base.OnDisconnected(stopCalled);
      }









      share|improve this question















      My C# method 'OnConnected()' in my Singal R hub class calls



      Clients.All.setConnectionStatus(profileId, true);


      with every page load and login!



      With my 'OnDisconnected(bool stopCalled)', if there is a logout I check for 'stopCalled', which gets set to false with a logout and true for a page load. Is there anything I can do in the 'OnConnected' method to check the same thing? ex. 'bool startCalled' which just looks for a login and not a page load!



      Because currently, with every page load, I have to send out a 'setConnectionStatus', which is seemingly redundant and an overkill.
      Isn't there a way to just look for a login similarly with the 'OnDisconnected' ?



      public override Task OnConnected()
      {
      string profileId = Context.User.Identity.Name;
      _connections.Add(profileId, Context.ConnectionId);
      Clients.All.setConnectionStatus(profileId, true);
      return base.OnConnected();
      }

      public override Task OnDisconnected(bool stopCalled)
      {
      string profileId = Context.User.Identity.Name;
      _connections.Remove(profileId, Context.ConnectionId);
      if (stopCalled == false) // log off only
      Clients.All.setConnectionStatus(profileId, false);
      return base.OnDisconnected(stopCalled);
      }






      c# asp.net-mvc signalr signalr-hub






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 22:16

























      asked Nov 8 at 23:45









      user1186050

      2,105933108




      2,105933108





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217834%2fcreate-a-signal-r-hub-onconnected-with-startcalled%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217834%2fcreate-a-signal-r-hub-onconnected-with-startcalled%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma