DEV Community


How to make your ✨shiny new ASP.NET Core 3.0 API accessible from emulators and within your network πŸ‘€

hminaya profile image Hector Minaya ・2 min read

You've just started a new project and decided you want to try out core 3.0 for your API πŸ‘.

File -> New ... Run your API and you are instantly showered with JSON test data πŸ‘‡

Alt Text

Great work πŸ’ͺ.

There is just one problem, if you are building this backend for a mobile app, you'll immediately run into that Aha moment, where you instantly remember that you can't access localhost from the emulator πŸ‘‡

Alt Text

No problem, I'll just change "localhost" to the actual IP of my laptop and that will be the end of it 😎

Alt Text

Nop, nice try. That will get you one step closer, but now we are dealing with another problem πŸ™ƒ.

What is going on πŸ˜”? The problem here is that IIS Express (used by default in VS2019) is only mapping requests for that port to "localhost".

Luckily this is very easy to fix πŸ‘‡

1️⃣ Open up the .vs folder πŸ“‚

It is in the root of your solution. It's hidden by default, make sure to enable "Hidden items" in Explorer.

Alt Text

2️⃣ Fire up Visual Studio Code πŸ”₯

Once inside, go to .vs[Your solution name]\config\ and find the applicationhost.config file. Open it up with VSCode.

3️⃣ Change the Bindings β›“

Specifically we are looking for the bindings that are using the same port number and are pointing to localhost. It should look something like this πŸ‘‡

          <binding protocol="http" bindingInformation="*:53391:localhost" />
          <binding protocol="https" bindingInformation="*:44310:localhost" />

Since this is our dev box, and we would like to make things easy on ourselves, I'm just going to change bindings to allow all.

          <binding protocol="http" bindingInformation=":53391:" />
          <binding protocol="https" bindingInformation=":44310:" />

4️⃣ It Works!!! πŸ‘πŸ‘πŸ‘

Save, Re-launch your API and refresh the browser on your emulator!.

Alt Text

Discussion (0)

Editor guide