question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.Net Core Console connect signalR 401 under windows authentication

See original GitHub issue

Describe the bug

When .net core signalR console app connect signalR server with Windows Authentication, receive 401.

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core netcoreapp2.1 with Windows Authentication enabled.
    [Authorize]
    public class TimeHub: Hub
    {
        public async Task UpdateTime(string message)
        {
            if (Clients != null)
            {
                await Clients?.All.SendAsync("ReceiveMessage", message);
            }
        }
    }
  1. .Net Core Console App
    class Program
    {
        static Action<string> OnReceivedAction = OnReceived;
        static void Main(string[] args)
        {
            Console.WriteLine(WindowsIdentity.GetCurrent().Name);
            //WindowsIdentity.RunImpersonated(WindowsIdentity.GetCurrent().AccessToken, Connect);
            Connect();
            Console.WriteLine("Hello World!");
            Console.ReadLine();
        }

        private static async void Connect()
        {
            var hubConnectionBuilder = new HubConnectionBuilder();
            var hubConnection = hubConnectionBuilder.WithUrl("http://localhost:61045/timeHub",options => {
                options.UseDefaultCredentials = true;
            }).Build();
            await hubConnection.StartAsync();
            await hubConnection.SendAsync("UpdateTime", $"From Client");
            var on = hubConnection.On("ReceiveMessage", OnReceivedAction);
            Console.WriteLine($"Client is Start");
            Console.ReadLine();
            on.Dispose();
            await hubConnection.StopAsync();
        }

        static void OnReceived(string message)
        {
            Console.WriteLine($"{ message }");
        }
    }

Expected behavior

Console App connect signalR server correctly.

Current behavior

Receive error 401 at console app.

Update:

After making a test with https and http url in client signalr, it works with https url, it seems app.UseHttpsRedirection(); at server side fail to redirect the client credential while redirecting http to https.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

0reactions
mikaelm12commented, Mar 5, 2019

Closing this as we haven’t heard from you in a little while. Please feel free to comment if you’re able to get the information we’re looking for and we can reopen the issue if we’re able to identify the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

iis - Asp.Net Core SignalR with Windows Authentication (401)
I am currently initializing the Hubs like this:Hub = new HubConnectionBuilder() .WithUrl(navMan.ToAbsoluteUri(hubPath), options => { options.
Read more >
Authentication and authorization in ASP.NET Core SignalR
In a hub, authentication data can be accessed from the HubConnectionContext.User property. Authentication allows the hub to call methods on all ...
Read more >
SignalR authorization not working out of the box in asp.net ...
This validation is done only when the connection is established. During the life of the connection, the server doesn't automatically revalidate ...
Read more >
Guide for authenticating Azure SignalR Service clients
Learn how to implement your own authentication and integrate it with Azure SignalR Service by following the e2e example.
Read more >
Authentication and Authorization for SignalR Hubs
NET client, such as a console app, which interacts with a hub that is limited to authenticated users, you can pass the authentication...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found