Skip to content

Azure SignalR service IHttpContextAccessor context always null #12535

@wpitallo

Description

@wpitallo

Hi, I have just converted my SignalR project to use AZure SignalR Service.

I am able to connect, and I can access the context from inside my hub, however, I cannot now access the context from outside of the hub.

Previously I used IHttpContextAccessor (see below) and this worked until I made the change to uas Azure SignalR service. Now everything works as it did before but the context being injected using the IHttpContextAccessor is always null.

Is there another way (or documentation) on how to access the context using Azure SignalR service from outside of the hub?

public class UserHelper
    {
        private readonly IHttpContextAccessor _context;

        public UserHelper(IHttpContextAccessor context)
        {
            _context = context;
        }

    public string GetUserToken()
    {
      return _context.HttpContext.User.Claims.FirstOrDefault(c => c.Type == "access_token")?.Value;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions