Home>

There is a pain point when developing web applications with c#,That is, when the web application debugging is started on the local machine, the external machine cannot access the web application. Here will introduce how to allow local and external network machines to access the web application through the settings.

table of Contents

Set up intranet access Set up extranet access

1. Set up intranet access

Before setting,The local environment is as follows:

operating system:win7

ide:visual studio 2010

application:asp.net

Wanting to enable other machines in the local area network to access the native web application includes the following 4 steps:

Step 1:Set the startup method to iis express

visual studio runs its web application by default using its own visual studio development server.So first change the project to use iis web server.

step:Right-click the web project → Properties → web tab → check Use local iis web server → set the port and click the [create virtual directory] button

Step 2:Set applicationhost.config file for iis express

After clicking the [Create Virtual Directory] button above, it will be displayed inof iis expressapplicationhost.configfile creates virtual directory information.

File default path:%userprofile%\ my documents \ iisexpress \ config \ applicationhost.config

Find the configuration information for the application above,Add a<binding>:

<binding protocol="http" bindinginformation="*:8081:*" />

sample graph:

note:If iis express has been started before modification, you need to restart iis express after modification to take effect.

Step 3:Set up a windows firewall

After completing the above 2 steps, you also need to set up a firewall to allow this port to pass.

1) Graphic operation:

Open advanced settings for windows firewall:

① Control Panel → Windows Firewall → Advanced Settings

② Create an inbound rule:protocol tcp, port 8081.

sample graph:

2) Command line

You can also execute the following command to add an inbound rule:

netsh advfirewall firewall add rule name=\ "command line web access 8081 \" dir=in protocol=tcp localport=8081 action=allow

result:

Step 4:Configure URL retention

In Windows 7, you can use the netsh.exe tool to configure the http settings, allowing specified URLs to pass.

Run cmd command as administrator:

netsh http add urlacl url=http://*:8081/user=everyone

This command adds a url reservation to the specified url namespace for all accounts

More netsh information, you can visit related msdn:Configure http and https

Operation diagram

2. Set up Internet access

After setting up the intranet to be accessible,Want friends from outside the network to access this machine,There are two methods:

1) Port mapping

2) Intranet penetration

2.1 Port mapping

Prerequisite:Have router setting permissions.

Set a port mapping rule in the external router.Go to the LAN machine when accessing the external IP address.The specific operation is not explained here.

2.2 Intranet penetration

When developing web applications in a company, not everyone can apply for port mapping permissions,So at this time there must be a solution for intranet penetration.

There are many applications that provide intranet penetration on the network.Here is usedPeanut shells(Official website :).

Example:

Operation diagram

c
  • Previous C # assembly and reflection
  • Next Flappy bird mini game example code in pure JavaScript