OWIN self hosted doesn't receive connections from outside - asp.net

I have a project which is made of a console application which listens to a port and acts when a message is received.
The messages are received from an asp.net web api based web site.
Both work properly together.
I wanted to combine both solutions into one executable file.
To accomplish that I used OWIN self hosted solution.
I managed to merge the web site into the console application and when working from my local machine I manage to see the web site and everything works well.
The problem occurs when I try to open the website from another machine\device connected to my LAN.
I get no response. I know it is not a firewall issue since my OWIN self hosted using the standalone website's port (I put the website down to make the port available).
This problem didn't occur when both solution where seperate.
I assume it is an owin configuration issue.
I tried to use the following code but I get access denied exception.
options.Urls.Add($"http://{Dns.GetHostName()}:{port}");
options.Urls.Add($"http://localhost:{port}");
If I use only
options.Urls.Add($"http://localhost:{port}");
There is no exception and it works from my computer as expected but not from another machine.
I did some search but didn't manage to make it work.
Any kind of assistance will be appreciated.
Thanks in advance!

you can either use specific ip-address or use * to listen on a port
I use below code for specific ip-address
var ip = Dns.GetHostEntry(Dns.GetHostName());
var ipaddress = ip.AddressList.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);
options.Urls.Add($"http://{ipaddress}:{port}");
or you can also do
options.Urls.Add($"http://*:{port}");

Open the ports on the firewall and
instead to use it
WebApp.Start("http://localhost:8080/");
Use it:
WebApp.Start("http://*:8080/");

Related

Unable to connect to webservice using Chrome Advanced REST Client but able to connect through chrome browser

I need to connect to a third party webservice. When I hit the link directly in the chrome browser, I am able to connect to it and I get a response. But when I tried the same using Advanced REST Client app of chrome, I get a message as 'The service's server DNS address could not be found.'
Also, when I tried to connect it via my JAVA code, using spring's rest template, am getting an Unknown host exception. What could be the reason that am able to connect via browser but not otherwise?
Thanks in advance.
Maybe it's a problem with your system's DNS settings? I'm not sure how Chrome handles queries to DNS when primary DNS did not found the record. If it uses Google DNS' then Chrome may connect to the service but other applications can't.
To test it set your DNS to 8.8.8.8 and check if apps start working.
From browser it's working properly but not from rest client or application, then i guess the problem with the proxy.
if you are using your office network, then this issue will come.
Try hitting the webservice by connecting to personal network.
i have faced similar issue last week, from browser and postman i'm able to hit the web service but not from the application.
Ones i connected with my personal then it started working.
Hope it helps.

IP instead of localhost

I have a sample project (using a webserver) working on localhost:49350
I would like to access that from another computer in the same network. However, entering the IP address instead of localhost (the one i get via cmd--> ipconfig) does not seem to work
(192.168.0.17:49350). I get a bad request (400).
Can anyone help? I am using asp.net web api and I am fairly new to this.
Thanks in advance!
Greets.
Try to open the port (49350) on your router, should be open for TCP.

SignalR self hosting with owin

I want to create an signalr app that will be self hosted using Owin, so to start off i tried to run the sample that is on https://github.com/SignalR/SignalR/wiki/Self-host. But when i run the application and then navigate to /signar/hubs i get a 500 Server error. I get the same exception when i try to connect from my client app.
Do i need to add something else apart from what is in the sample code? or does anyone know of a good tutorial?
Things to check if trying to access from an external connection:
Are you hosting the server on all addresses or just localhost?
// use http://*:8080 to bind to all addresses.
string url = "http://localhost:8080";
Make sure to run app as administrator.
Also, is the Windows firewall blocking the port you are using? I had to add an exception to allow incoming TCP connections on that port.

Hosting WCF web service from a Remote Server

I have an WCF Webservice project, built in my local machine, which when hosted using test client and triggered, returns values from remote database in JSON format.
For example, if you key in the URL with localhost then you get results back in the below format:
{"Id":3,"Value1":"67.5687","Value2":"126.7125"}
I want to host this project on a remote server with a public URL, which should return the above results back from any network. I have 3 question regarding this:
** What modifications should I do to my current WCF project to host it on remote server.
** Given the various types of hosting like :
1) windows process activation services (WAS)
2) IIS
3) Self hosting
4) Hosting in a Windows service,
which type of hosting is best suited for hosting on remote server.
** What changes should I make in my App.Config file (including the change in my endpoint address from localhost to IP address) to make the service work.
Thanks.
1) You shouldn't need to make any changes to your project just because you want to host the code on another machine. I find this an odd question.
2) Given your choice of JSON as data format and a browser as test client, I'm guessing you want to make it available over HTTP using simple GET requests. In the Microsoft stack, IIS is the web server, and the natural choice for this scenario.
3) It is quite impossible to answer. I don't know what's in your app.config today. I don't know if you're going to authenticate, and if so how. And I don't want to know! That said, it seems to me if everything is supposed to behave as it does on your dev box, the bindings are already ok. I don't remember if a WCF service needs to know about the endpoint it is itself at (hard to see why it would need to know this, really); I would have thought it more natural to do such configuration on the host, e.g. IIS. The client of course should use a different endpoint pointing to wherever you host the service. (You can put many endpoints in app.config and let the user choose one, btw.)
I think most of us sin against the following advice now and then, but it is the best advice I can give: Read a book. Learn as much as possible about the thing you're using, in this case WCF. You'll get the time back later, and your software will be less bad!

ActiveDirectoryMembershipProvider "The specified domain or server could not be contacted."

I have an application that is using ActiveDirectoryMembershipProvider to grant access to users. The application is hosted on a non-domain machine, with a firewall between the application server and the domain controller.
We've opened the LDAP port to the DC on the inside network - yet no matter what we try, we end up with an error that says "The specified domain or server could not be contacted."
Does anyone have any suggestions on how I can resolve this? We've tried everything we can think of and just aren't getting anywhere.
My connection string is:
<add name="ADConnectionString"
connectionString="LDAP://10.5.3.7:389/DC=MyTestDomain,DC=local"/>
And my provider is:
<add name="ActiveDirectoryMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider"
connectionStringName="ADConnectionString"
attributeMapUsername="SAMAccountName"
connectionProtection="None"
connectionUsername="LdapUser"
connectionPassword="LdapPassword" />
The application is hosted on a non-domain machine, with a firewall between the application server and the domain controller.
Since you could query directly using an LDAP tool, that suggests that the firewall is open correctly. However, keep in mind that the ActiveDirectoryMembershipProvider is not using plain old LDAP, it's using Microsoft technologies. For example, if you set connectionProtection="Secure", ADMP will try using SSL and port 636, if that fails, it will use Microsoft's built-in IPSec signing (see this article for more details).
Anyway, this makes me wonder about a couple things:
Does the AD domain have an IPSec "required" policy which refuses connections from non-domain/non-configured computers? (Probably not, since you connected with plain LDAP, but it's worth investigating.)
Have you added the domain controller's NetBIOS name to your lmhosts file, and its DNS name to your hosts file? (Many protocols check that their target's reported name matches the name you tried to connect to.)
A lot of people have noted problems using ADMP between different domains, and the solution required that a one-way trust be created. Since it sounds like your client computer is not in a domain, you can't have that trust--unless either (a) it is a member of a different domain with a one-way trust or (b) it is a member of the same domain and thus client-server trust is implicit.
It seems like the solution is to open port 445.
Read this thread
We're not allowed to open so I guess I'm stuck.
You can use this two articles, may be solve your problem
www.ddj.com/windows/184406424
forums.asp.net/t/1408268.aspx
and check your firewalls
I had this error, and managed to fix it. There are multiple reasons that can lead to this, here is a to-do list to identify exect problem:
Create a micro application, with single method Membership.GetAllUsers(), execute on machine outside Active Directory (AD), with incorrect password in connection string, check if you get incorrect password exception. If you don't get it you can't connect to your AD server, check firewall, if you do get invalid password exception, goto next step.
If you can, try to execute same app, localy on AD server, first with incorrect password, than with correct, executing app locally provides more detailed exception what is wrong (for me this exception lead me to fixing problem). In my case it told me that Server service is not started, than that Workstation service is not started.
Some thoughts on the fact that it required Server and Workstation services to be working on server: afaik Server service is used for windows file sharing (netbios over TCP), and is using 445 port, so it mey be that this port must be opened in addition to LDAP port. My second observation was that event if 445 port opened (netstat -an) it still can be not working, winows will drop all packets to this port if Windows Client and File and Printer sharing checkboxes are not checked on network interface adapter which rcived this packets. Check "telnet External_IP 445". Thats all info i gathered while strugling with this problem.
Have you tested with an LDAP browsing tool, from the remote box to see if it can connect with the criteria being used here? I.e. Is it a connectivity problem or something else?
In case anyone stumbles on this and wants to smash their head on a wall... Recently tried doing all this for an AD server that my company had in a different domain than the current context. Was using the IP provided and getting failures as stated here. Even used a tool like Softerra LDAP Admin and it worked fine, however AccountManagement failed.
We had a publicly exposed URL hooked to that IP address (still only allowing certain IP's to make calls). Once I replaced the IP with the URL provided, it worked like a charm.
Hope this saves someone the hours of head smashing I just put myself through.

Resources