SignalR Client - The remote server returned an error (401 Unauthorized)

10,358

Solution 1

I was able to solve what seems to be the problem. With the SignalR.Client the URL you need to give in the connection string looks like this:

private static Connection WebUIConnection = new Connection("http://localhost:54193/IISWebsite/signalr/hubs");

In addition to this I had to provide it with my local admin username and password for it to be able to connect. This is not how it should be done I feel, and I'd appreciate if anyone can enlighten me on how to make the network user have access to IIS from a local machine.

However, I think making a separate administrator account and making my windows service run under that account in the production environment is a solution I'm willing to accept. This way, it will be able to connect to the local IIS without a hitch.

Hope this information is helpful to others :)

Lari

Solution 2

If you're using hubs then that code is incorrect. There's a HubConnection you should be using. More info here:

https://github.com/SignalR/SignalR/wiki/SignalR-Client-Hubs

Share:
10,358
Lari Tuomisto
Author by

Lari Tuomisto

Updated on August 01, 2022

Comments

  • Lari Tuomisto
    Lari Tuomisto almost 2 years

    Premise

    I'm attempting to make a windows service act as a signalR client to a web server (MVC3 project running on IIS Express). When trying to connect to the server, a 401 Unauthorized is returned.

    Now, as far as I understand, the windows service runs under the account NETWORK_SERVICE, and it makes sense that this is not a valid user name to connect to the IIS. However, I've tried configuring SignalR in the following way:

    Init

    private static Connection WebUIConnection = new Connection("http://localhost:54193/IISWebsite");
    

    Set credentials

    WebUIConnection.Credentials = new System.Net.NetworkCredential("?", "?")
    

    The settings of the IIS: The IIS is almost a standard MVC3 project, and it has windows authentication enabled.

    What I've tried

    I've tried setting SignalR's credentials as my local windows username + pw, and also tried using the local network AD uname + pw, but I don't see this as being the way to do it.

    So what I'm asking is, what should I consider when I try to make my windows service act as a client to the signalR-server, and is there a way to configure IIS to give client access to the Network_Service user? Is it in fact possible to make a windows service act as a client to a web server running in IIS like I'm trying to do?

    Thanks, Lari

  • Lari Tuomisto
    Lari Tuomisto over 12 years
    Furthermore, If you guys have problems with the SignalR.Client which you got from Nuget. The SignalR.Client version actually uses Newtonsoft.Json version 4.0.3 instead of the 4.0.5 version which Nuget downloads. To fix this issue, type to Nuget Console: Uninstall-Package Newtonsoft.Json -Force Install-Package Newtonsoft.Json -Version 4.0.3
  • jazzy
    jazzy over 11 years
    The solution proposed here (stackoverflow.com/questions/9722983/…) worked for me. It uses the default network credentials.