简体   繁体   中英

Web API Self Host public IP

I am trying to access a Web API Service written by me (currently hosted in a Console Application for ease) from anywhere without using a DDNS service. I know that the public IP could change, it doesn't matter. I will always have access to the new one. I'm just doing this for the fun of it.

So far, I did the following things:

  1. I set a static IP in the DHCP of the router (in this case 192.168.1.101);
  2. Added a port forwarding from and to the 50000 port(easier to make sure I don't confuse things around);
  3. Added an inbound rule for the 50000 port on the firewall with "allow the connection" set;

The service is set to start on the address 192.168.1.101:50000 all the time. Also Cors is set to CorsOptions.AllowAll

Here comes my problem: when I make a request using Postman to the API using the local ip address and port, everything works as expected.

However, if I try accessing the public IP address with the same port, like so: public_ip:50000/ApiRoute I get a timeout regardless of the device (local machine or other device connected on same network or different) I make the request from;

The source of the public IP address is the ifconfig.co website.

Does anyone have any idea why the public IP doesn't work? I'm honestly out of ideas.

Try just putting an asterisk (*) in the base URL to be sure the API can be accessed from any IP address, just like this code:

using Microsoft.Owin.Hosting;
using System;

namespace WebApiDocker
{
    class Program
    {
        static void Main(string[] args)
        {
            string baseAddress = "http://*:80/";

            using (WebApp.Start<Startup>(url: baseAddress))
            {
                Thread.Sleep(Timeout.Infinite);
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM