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

醉酒当歌 提交于 2019-12-10 16:48:23

问题


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


回答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




回答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



来源:https://stackoverflow.com/questions/8503963/signalr-client-the-remote-server-returned-an-error-401-unauthorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!