There is a pain point when developing web applications using C#, which is that external machines cannot access the web application when using VS to enable web application debugging on this machine. Here we will introduce how to allow LAN and external network machines to access local web applications through settings.
Directory
1. Set up intranet access
2. Set up external network access
1. Set up intranet access
Before setting up, the local environment is as follows:
Operating system: win7
IDE: Visual Studio 2010
Application: asp.net
Wanting other machines in the LAN to access the local web application involves the following four steps:
Step 1: Set the startup mode to IIS Express
When Visual Studio runs the web application, it is used by default Own Visual Studio development server. So first we need to change the project to use IIS web server.
First make sure that the machine has IIS Express installed, download address (version 10.0): www.microsoft.com/zh-CN/download/details.aspx?id=48264
Steps: Right click Web project → Properties → Web tab → Check Use local IIS Web server → Set the port and click the [Create virtual directory] button
Step 2: Set up IIS Express applicationhost.config file
After clicking the [Create Virtual Directory] button in the above operation, the virtual directory information will be created in the applicationhost.config file of IIS Express.
Default file path: %userprofile%\My Documents\IISExpress\config\applicationhost.config
Find the configuration information of the above application and add one:
<binding protocol="http" bindingInformation="*:8081:*" />
Example picture :
Note: If IIS Express has been started before the modification, IIS Express needs to be restarted after the modification to take effect.
Step 3: Set up windows firewall
After completing the above 2 steps, you also need to set up the firewall to allow this port to pass.
1) Graphical operation:
Open the advanced settings of Windows Firewall:
① Control Panel → Windows Firewall → Advanced Settings
② Create an inbound Rules: Protocol TCP, port is 8081.
Example picture:
2) Command line
You can also execute the following command to add an inbound rule:
netsh advfirew all firewall Add rule name=\"命令行Web访问8081\" dir =in protocol=tcp localport=8081 action =allow
Result:
Step 4: Configure URL reservations
In Windows 7, you can use the Netsh.exe tool to configure HTTP settings to allow specified URLs pass.
Run cmd command as administrator:
netsh http add urlacl url=http://*:8081/ user=everyone
This command adds a URL reservation for the specified URL for all accounts Namespace
More For netsh information, you can visit the relevant MSDN: Configuring HTTP and HTTPS
Run diagram
2. Set up external network access
Set up internal After the network is accessible, friends who want to access the machine from the external network can use the following two methods:
1) Port mapping
2) Intranet penetration
2.1 Port mapping
Prerequisite: Have router setting permission.
Set a port mapping rule in the external router to jump to the LAN machine when accessing the external IP address. The specific operations are not explained here.
2.2 Intranet penetration
When developing web applications within the company, not everyone can apply for port mapping permissions, so at this time there is a solution for intranet penetration .
There are many applications on the Internet that provide intranet penetration. The one used here is peanut shell (official website: hsk.oray.com/).
Example:
Note: When WeChat OAuth2.0 performs domain name jump, the port number will be added. At this time, the domain name port is 80 and the local port is 8081, and the address after the jump is domain name: 8081, an error will be displayed. The solution is to set the port of the native web application to 80.
Run Chart
The above is the detailed content of Steps to enable external access for C# web application debugging. For more information, please follow other related articles on the PHP Chinese website!