I was trying to access my localhost ASP.NET Core MVC website from another computer which sits in different LAN. Thus, I tried to google around and it does show some good solutions, however, I would need to refer to multiple places to get the final solution. So, I thought I could just compile them in one single post, in case there are some people looking for one-stop solution. FYI, This solution is only for Windows 7 or Vista.
1. Configure Windows Firewall
In my case, I will need to make sure that my Windows 7 firewall to open for that port number, for instance, 51841. You will need to add a rule in your Windows Firewall in Inbound Rules like below. Just select New Rule...
Choose Port and click Next button
Choose TCP and enter 51841 (or whatever port number you wish) in Specific local ports
Choose Allow the connection
For profiles, it depends on your environment. In my case, I will check all three.
And finally, pick a name for this rule. In my case, I will put down my website name for easy reference later.
Once added, your new inbound rule will appear in the list.
2. Enable remote connections on IIS Express
By default, remote connections are disabled on IIS Express. To enable it, simple execute the following command from an administrative prompt (Right click and choose Run as administrator):
netsh http add urlacl url=http://*:51841/ user=everyone
In the command, replace 51841 with your own port number.
netsh is a powerful tool to modify network configuration of computer. If you are interested, learn more from this article.
3. Modify applicatonhost.config
However, you may come across the HTTP 503 Invalid hostname error. To resolve this, locate $(solutionDir).vs\config\applicationhost.config file. (solutionDir) would your ASP.NET Core MVC project folder path. To be able to see .vs folder, make sure you allow hidden folder to be visible.
<binding protocol="http" bindingInformation=":51841:localhost" />
and replace with
<binding protocol="http" bindingInformation="*:51841:*" />
Once it's done, it's better for you to restart your Visual Studio.
And that's it, you should be able to browse your website from anywhere, for example, http://[mypcname]:51841/
Please let me know if you have any questions, comments, or concerns below.