How to access your localhost website from external LAN?
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, simply 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).vsconfigapplicationhost.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.
Locate <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,
Please let me know if you have any questions, comments, or concerns below.
How to use ASP.NET Identity with ASP.NET Web Service and ASP.NET MVC?
ASP.NET Identity is much more powerful than legacy ASP.NET Membership which includes the support of external authentication from 3rd party providers. In one of my projects, I have an ASP.NET MVC app communicating with another ASP.NET Web Service app which contains all core business logic and data access. The MVC application essentially is just another Presentation Layer which handles simple rule processing. While I was trying to migrate to ASP.NET Identity, I was stuck on trying to decouple database access from ASP.NET Identity, specifically the SignInManager class in the MVC application.
Peculiar case of “Unable to connect to web server ‘IIS Express'”
There was one particular ASP.NET Core project that I have left it for quite a long time. Therefore, I would need to refresh my memory in order to understand how it works by first running it in debugging mode in Visual Studio 2017. To my suprise, as soon as I pressed F5, there was a popup error as below: