VS2015 uses IIS Express to support non-localhost access

Use VS2015 to develop C# web projects, and use IIS Express as the server. It is no problem to develop by yourself and test by yourself, and let other people access the test

Bad Request - Invalid Hostname


HTTP Error 400. The request hostname is invalid.


My machine can be accessed by both the local area network and the public network. There is a local area network ip 192.168.8.110, and port mapping is done on the router, and port 5678 is mapped to port 5678 of this machine.


Regardless of using the 192-segment ip, or the public network ip, or 127.0.0.1, the above error occurs.


Baidu:

http://www.cnblogs.com/liluping860122/p/4685564.html

Found a hero's solution, well written.

The main thing is to modify: the applicationhost.config file under the project path\.vs\config folder, find the site node, and modify the bindings property, which is actually the same as editing bindings in iis.

There are a few specific changes to note:

1 If the actual public domain name is used

<binding protocol="http" bindingInformation="*:9999:localhost" /> localhost can be directly replaced with a public domain name, vs does not need to be opened with administrator privileges

2 If you use a custom domain name

Localhost is replaced with a custom domain name. If you open it with administrator privileges, you don’t need to edit the hosts file of the system. If you open it with normal privileges, you need to edit the hosts file.

I am a win7 system, and the hosts file is hidden under C:\Windows\System32\drivers\etc, so I need to choose to display hidden folders from the system menu-tools-folder options-display.

When I am modifying, the installed anti-virus software Xiaohongsan prevents modifying the host, and I can save it if I choose to allow it. Otherwise, it will prompt that other files are being opened and will not allow saving.

3 If using LAN ip

Just replace localhost with a specific ip. Note that you must open vs with administrator privileges. Otherwise it is still impossible.


After modifying the config, restart VS. When restarting, choose whether to run as an administrator. After opening VS, run the project, you can see the IIS express tray in the lower right corner - view all running programs, there will be the ip you just set .


After the LAN ip can be used, my external network ip can be used automatically.

Guess you like

Origin blog.csdn.net/small_tu/article/details/50961478