DEV Community

Hector Minaya
Hector Minaya

Posted on

How to make your โœจshiny new ASP.NET Core 3.0 API accessible from emulators and within your network ๐Ÿ‘€

You've just started a new project and decided you want to try out asp.net 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 ๐Ÿ‘‡

 <bindings> <binding protocol="http" bindingInformation="*:53391:localhost" /> <binding protocol="https" bindingInformation="*:44310:localhost" /> </bindings> 
Enter fullscreen mode Exit fullscreen mode

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.

 <bindings> <binding protocol="http" bindingInformation=":53391:" /> <binding protocol="https" bindingInformation=":44310:" /> </bindings> 
Enter fullscreen mode Exit fullscreen mode

4๏ธโƒฃ It Works!!! ๐Ÿ‘๐Ÿ‘๐Ÿ‘

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

Alt Text

Top comments (0)