IIS express configuration to host websites – Raybiztech
Nội Dung Chính
Background
In order to use IIS to run websites on developer PC the developer must get administrator access on PC. But according to the company policies developer should not get administrator access on desktop computer.
The solution is use IIS express to run site on developer desktop computer.
1. IIS express configuration
- Download IIS express from the following link and install on developer PC
https://www.microsoft.com/en-us/download/details.aspx?id=48264.
Once it installed the IIS express configuration files will be available at “Documents\IISExpress\config” and IIS express execution files will be available at the installation directory.
EG: C:\Program Files\IIS Express;
Set environment variable path to “C:\Program Files\IIS Express”
Open advanced system settings -> Environment variables -> System Variables -> Path -> Edit ->New -> add the path C:\Program Files\IIS Express
Follow the instruction from following link to run a site using IIS Express
https://docs.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line2. Edit application host
Open the configuration file and add site configuration to the file
Eg:
<site name=”WebApplication1″ id=”6″>
<application path=”/” applicationPool=”Clr4IntegratedAppPool”>
<virtualDirectory path=”/” physicalPath=”E:\WebApplication1\WebApplication1″ />
</application>
<bindings>
<binding protocol=”http” bindingInformation=”*:8087:localhost” />
<binding protocol=”https” bindingInformation=”*:44333:localhost” />
<binding protocol=”http” bindingInformation=”*:80:mycustomdomain.com ” />
</bindings>
</site>
To run the site use the below command
iisexpress /config: C:\Users\<UserName>\Documents\IISExpress\config\applicationhost.config /site: WebApplication13. Start site using custom domain
Below configurations must be completed by a user with admin access on pc
Step 1: Edit the applicationhost.config file and add the custom domain binding to the configuration
Eg:
<site name=”WebApplication1″ id=”6″>
<application path=”/” applicationPool=”Clr4IntegratedAppPool”>
<virtualDirectory path=”/” physicalPath=”E:\WebApplication1\WebApplication1″ />
</application>
<bindings>
<binding protocol=”http” bindingInformation=”*:8087:localhost” />
<binding protocol=”https” bindingInformation=”*:44333:localhost” />
<binding protocol=”http” bindingInformation=”*:80:mycustomdomain.com ” />
</bindings>
</site>
Step2: Open command prompt as Administrator and run below command
Whoami- to get the current user name
netsh
http add urlacl url=http://mycustomdomain.com:80/ user=everyone or UserName
http add urlacl url=https://mycustomdomain.com:443/ user=everyone or UserName
quit
Step 3: Start the site using below line
iisexpress /config: C:\Users\<UserName>\Documents\IISExpress\config\applicationhost.config /site: WebApplication14. Debug site on Visual studio
Start the site using the command
iisexpress /config: C:\Users\<UserName>\Documents\IISExpress\config\applicationhost.config /site: WebApplication1
Now open visual studio -> debug -> attach process -> attach iis express process.
Now debug the code as usual.
Configure IIS express on visual studio
Select the web application project and open properties -> select the web tab -> under server’s select IIS express-> Specify the project URL.
Now open the project folder and .vs folder (Hidden) -> Config -> applicationhost.config and make required configuration changes as detailed above.
Delete Url reservation
Use the below command to delete the URL reservation
netsh http delete urlacl http://mycustomdomain.com:80/
Select the web application project and open properties -> select the web tab -> under server’s select IIS express-> Specify the project URL.Now open the project folder and .vs folder (Hidden) -> Config -> applicationhost.config and make required configuration changes as detailed above.Use the below command to delete the URL reservationnetsh http delete urlacl http://mycustomdomain.com:80/