SignalR with .net core CookieAuthentication on Domain issue - c#

First off, I know very little about signalR. I'm trying to learn and I'm just messing around mostly.
Running on .NET Core 3.1.
I have 2 machines:
PC1 is my dev desktop with Win10 Pro and IIS which is on our domain.
PC2 is running Ubuntu (Not on the domain) with a Win10 VM which is on the domain.
I've created the Chat app from the Getting Started with SignalR.
If I host this in IIS on PC1 it all works fine. The SignalR connection is established and I can send messages from PC1, PC2 Ubuntu, PC2 Win10 VM, and even my phone. Any device on the network can connect to the hub just fine while there is no authentication in place.
If I add Cookie Authentication loading the site will redirect to the login page, login will be successful, and the user will be redirected back to the main index page.
However, only a machine that is part of the domain can establish a SignalR connection after login. This means PC1 can login and establish a signalR connection and send messages.
PC2 ubuntu can login, but get an Unauthorized error when trying to establish a SignalR connection.
PC2 ubuntu/Win10 VM (Which is on the domain) can login, but get an Unauthorized error when trying to establish a SignalR connection.
Using my phone I get the same Unauthorized error.
If a work colleague, who is part of the domain, loads the site on his machine, he can login and establish a working SignalR connection.
When authentication is active, no device that is NOT part of the domain can establish a working SignalR connection.
Any device that is NOT part of the domain get a Unauthorized 401 error when trying to establish a connection to the Hub after login.
Any device that IS part of the domain can login and establish a working SignalR connection with no errors.
The code seems to work fine. I'm thinking it's an IIS issue. My IIS setup is based on this:
https://damienbod.com/2018/09/21/deploying-an-asp-net-core-application-to-windows-iis/
It all seems to work and run fine as far as the code is concerned, but a device that is NOT part of the domain cannot establish a signalR connection when Authentication is active.
If there is no authentication, ANY device on the network can connect to the hub just fine.
Again, this is just me messing around and trying to learn what I can or cannot, OR, should or should not do. And yes, I did Google this A LOT.
My Startup code:
Login code:
Hub code:

I got it working... posting this in case it might help someone else and spare them many days of getting nowhere :)
It turns out the Windows domain does not play a role. None of the devices/machines on the network can make a signalr connection over the network if I have authorization active in the app. Only the machine where the IIS is running can open the app, login, and make a signalR connection and work as intended.
Yesterday I happen to watch a video about publishing .net core apps to IIS in Win10 and the guy created a new site under IIS instead of creating a new application under the Default Site that comes with the IIS install.
Decided to give this a go and sure enough the app started working when hosted under a new site in IIS.
I don't know if there is a setup issue on the Default Site... I'm the only one that uses this IIS install and I know I didn't change any of the Default Web Site settings. The win10 install is also only about 6 month old.
I want to test with a fresh install of IIS on a Win10 laptop we have here at work to see if the same issue comes up... I doubt it, but might be worth checking anyway.

Related

Connect device on LAN to ASP.NET Core Web API

I'm running VS2019 community, and I've created the default ASP.NET Core Web API project (ASP.NET Core 5.0), the one with the simple weather forecast example. And I am now trying to connect another computer to the URL. I run the example by using the [application name] in the run dropdown, and not IIS Express.
Both computers are connected via wifi to the same Router.
I do an ipconfig on the server machine to get it's IP (192.168.1.108)
And I have also enabled inbound connections from the ports 5000-5001 in the windows firewall setup
On the "client" machine I try to access the server with :
http://192.168.1.108:5000/swagger/index.html
or
https://192.168.1.108:5001/swagger/index.html
but neither seem to work? The page ends up timing out.
So on the machine running the server, I also completely disabled the windows firewalls (temporally, just to get things working).
But still get the same result?
Have I missed a step?
Maybe this will help you. Try to add IP of your host into Program.cs
var host = new WebHostBuilder().UseUrls("http://192.168.1.108:5000")

Connecting to IIS local server via android emulator (ASP.NET MVC)

I have ASP.NET MVC website that runs on my local sever and I need to check mobile area.
So I decided to connect to it via Android Emulator (AVD)
As I read IIS server reject incoming requests from remote devices.
So from this thread I think I found solution
Post
I make all described on his github and get this
So as I understood it can receive external requests now.
And I tried to make request from AVD (192.168.2.106:3000)
And I get this
So as I understood it got path, but IIS still not receive external request.
Maybe someone faced this problem and can help me solve it?

403 Error For Web Service Call

I am using a 3rd-party tool that runs as a Microsoft Service on a Windows Server 2008 R2 machine. The machine is using a Dell SonicWall firewall. The tool has defined ports that it is listening on of which I have opened one. Using an external web tool that port is listed as open. The service has been installed and shows as running when I run services.msc.
Everything runs great on my local machine. However, when I try to query the service I get a 403 error. The following is what the query URL looks like:
https://{siteUrl}:{portNumber}/scanservice/v2/getstatus?method=jQuery111106758983342442662_1428439579840&_=1428439579841
This is an AJAX GET request coming from an ASP.NET MVC application.
The code attempts to find an open port by querying 3 ports that are the https ports for the service. The first two are ports that I have not opened on the machine. These queries time out which is what I would expect. The last port is the one I have opened on the server. I immediately get a 403 error.
Is there somewhere where I need to expressly allow that service, not just the port?
It is a case where your public IP is not whitelisted on the web service hosting server

consuming wcf on mvc project fails after published

I'm using a sms panel in my website which provides me with a api to use, when I'm debugging the system and use it locally it works perfectly but when I publish the website it gives the following error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 87.107.121.54:80
and this is the code I'm using
SendSoapClient client = new SendSoapClient("SendSoap");
ArrayOfString receivers = new ArrayOfString();
receivers .Add("0920xxxxxxx");
ArrayOfString result = client.SendSimpleSMS("username", "password", receivers, "sender number", "message goes here", false);
I've put the call to the web service inside my global.asax file just to check if it works or not and it just doesn't work. what exactly am I doing wrong here ?
P.S: I've used this api service in my other websites which are not mvc projects, but just asp.net website and they all are working fine, this is the first time using it in mvc project.
It appears that the computer you deployed your application to doesn't have network access to the 87.107.121.54 IP address which is where the API is hosted. So talk to your network administrator and make sure that the server on which your ASP.NET MVC application is running has network access to this address. Since it is on port 80, I suppose that there shouldn't be issues with the firewall, but nevertheless, you should check that as well. There's nothing wrong with your code, it's more of an infrastructure and network connectivity problem.

Consuming Asp.net web service from remote computer

I create Asp.net WS and host it on the IIS.Now i want to consume it from remote computer or another computer.When i insert the URL of the WS on the remote computer an error message appears inside internet explorer browser page says
This program cannot display the web page
i work on Visual studio 2008, windows 7 and the client application is Asp.net website.
i don't know what is the problem??
have i connect the two computers with LAN(make network between them) or just enough each one connect to the internet??
Your computers need to be able to connect to each other.
If they on LAN, then You need to specify LAN address for asp.net WS.
Also check Your firewall for blocking connections, need to be sure that port were IIS hosted is available for connection
If nothing helps, then provide us more information about problem.
Really i don't know what is the problem.When i do the same thing in another computer it runs but on my laptop doesn't run.

Categories

Resources