This article is shared from Http://www.cnblogs.com/polk6/archive/2017/01/03/6215659.html, where only records are made.
A pain point when developing web Apps in C # is that the external machine cannot access this web app when it is debugged with vs. Web application debugging. This will show you how to set up a web app that allows LAN access to native computer.
First step: Set startup mode to IIS Express
When Visual Studio runs a web app, it uses its own Visual Studio development server by default. So first change the project to use the IIS Web server.
First make sure the machine is installed with IIS Express, (10.0 version): https://www.microsoft.com/zh-CN/download/details.aspx?id=48264
Step : Right-click Web Project → properties →web tab → Check Use local IIS Web server → set port and click on "Create virtual directory" button
Step Two: Set the IIS Express ApplicationHost.config file
When you click on the "Create virtual directory" button above, the virtual directory information is created in the IIS Express applicationhost.config file.
file Default path :%USERPROFILE%\My documents\iisexpress\config\applicationhost.config
Locate the configuration information for the application above and add a <binding>:
<binding protocol= "http" bindinginformation= "*:1851:*"/>
Example Diagram :
Note : If you have started IIS Express before you modify it, you will need to restart IIS Express for the changes to take effect.
Step three: Set up Windows Firewall
After completing the 2 steps above, you will also need to set up the firewall to allow this port to pass (if you shut down the firewall, this can be omitted).
1) Graphics Operation:
Turn on advanced settings for Windows Firewall:
① Control Panel →windows firewall → advanced settings
② creates an inbound rule: Protocol TCP, Port 1851.
Example Diagram :
2) command line
You can also add an inbound rule by executing the following command:
netsh advfirewall firewall Add rule name=\"命令行Web访问8081\" dir=
in
protocol=tcp localport=8081 action=allow
Fourth step: Configure the URL reservation
In Windows 7, you can use the Netsh.exe tool to configure HTTP settings to allow the specified URL to pass.
Run the cmd command as Administrator:
netsh http add urlacl url=http:
//*:8081/ user=everyone
This command adds a URL reservation for the specified URL namespace for all accounts
Example Diagram :
With the above settings, you can ensure that you can access the network when debugging.
C # Web application debugging Open external access