TedTel
TedTel

Reputation: 5625

How to enable external request in IIS Express?

How can I enable remote requests in IIS Express? Scott Guthrie wrote that is possible but he didn't say how.

Upvotes: 551

Views: 428666

Answers (29)

Wasted_Coder
Wasted_Coder

Reputation: 1968

Using: Visual Studio 2022 and IIS Express

Problem: Trying to get IIS Express to serve remote http requests over the local network is a bit too much setup for these reasons:

  1. You have to run Visual Studio as 'admin', that is an unusual workflow.
  2. You have to make changes to the deeply buried applicationHost.config.
  3. You have to run netsh commands.

You have to do this for each dev project and copy of the project code that you have (like if you work on multiple branches at the same time, especially if you exclude the .vs folder from SVN/GIT for multi-team requirements).

Alternative Solution: Using a reverse proxy you can point any http request to a local web system (not just development projects). And the reverse proxies setup and configuration is very easy.

Benefits:

  1. You can easily update any settings when you start with a new project or need to change to a different port.
  2. You can add HTTPS with Let's Encrypt certificates (public ip needed).
  3. You can point external domains (DNS) to your local IPs to allow for easy remembering of the URL, or neatness.

Alternative 1: Using IIS Reverse Proxy (No 3rd-Party Tools Required)

This is my preferred option, as IIS comes with each copy of Windows XP and newer. You can read the Microsoft article for a detailed explanation of how it works.

Step 1: Install IIS and Needed Modules

  1. Go to Windows Features and enable IIS. To do this simply search for "Windows Features" on the start menu, and it pops up as "Turn Windows Features on or off".

Preview of the Windows Features option on the start menu.

  1. Enable IIS by checking "Internet Information Services" in the list. It will check the default options that is sufficient, the two modules that we need will need to be downloaded from the IIS website.

Diaglog to add IIS

  1. Download and install Application Request Routing and URL Rewrite 2.1 from the official IIS site.

Step 2: Setup ARR in IIS

  1. Open IIS, by searching for "IIS" on the start menu.

The IIS entry on the start menu

  1. Go to the Server Node (1) and then select the "Application Request Routing Cache" (2) option.

The ARR icon on IIS management module

  1. Then on the right hand side tray go to the option "Server Proxy Settings..".

Where to find Server Proxy Settings

  1. Check the option "Enable Proxy". The rest of the settings is fine. Choose "Apply" on the right hand side.

Checkbox for Enable Proxy

Step 3: Setup Reverse Proxy Site

  1. Select the "Default Web Site" in the list of Sites, and go to the "URL Rewrite" option.

URL Rewrite option

  1. Select the "Add Rule(s).." option on the right hand tray, and then on the dialog that pops-up select the "Reverse Proxy" option.

The add rule dialog

  1. Now here is a bit of an unclear step if you look at the description and sample text on the dialog. You enter **localhost:60622** (with the port number) as the server name that the requests is forwarded to. You find this here in Visual Studio (Right click on you web site project > Properties):

Find the port number here

It should look like this (The option marked as 2 does not work because the sites are compressed by IIS Express):

Preview of the host name to enter

Press enter to create the rule.

  1. That is it, now you can Run your project in Visual Studio and when the project website have loaded, you can access it from any device on the network by using your development PC's IP and no port number (since we used the default site).

Advanced Tips:

  • Keep Project Port Numbers: Because we are using IIS URL Rewriter to manage the reverse proxy forwarding, you can use IIS rewrite rules to create a rule that will "copy" the port number to the forwarded hostname and port, then you can simply add bindings to the site for each port number that matches your development projects numbers (since each Visual Studio project gets a new random port number). This way if you work with more than one project or copy of your system, you can just use the relevant port number on the remote PC to open that site once you have started it.

  • Switching Projects: If you don't follow this tip above, you will simply need to edit your URL Rewrite rule everytime you want to test another project site and then the default port (thus just the ip or host name of the developement pc) will point to that project.

  • Sync Project Port Numbers: If you don't run debug your sites at the same time, you can simply make their random ports the same, and then you don't need to update the URL Rewrite rule.

  • SSL: With the SSL offloading, this enables you to add an SSL certificate to the site (self signed) that is used for all the projects.

Alternative 2: Using iisexpress-proxy Reverse Proxy (You need Node.js)

This opton involves another reverse proxy solution. The only downside is that you need to have Node.js or npm. Since I'm an old school Asp.Net and C# developer, I don't have Node.js installed, and I prefer to keep my development environment clean.

If you have Node.js installed (or use 'npm' for other purposes already) this option is very easy to follow, just read the github instructions for how to set it up.

Effectively even if you install Node.js just to get this, it is still many times simpler than trying to get IIS Express to work accross multiple projects.

Alternative 3: Using Conveyor Reverse Proxy (3rd Party but Just Works)

This is a 3rd party tool, but one that is very well supported and have the backing of an organisation that has altertive income to fund the solution. So the solution is free to use, but you can pay for some extra features that is not part of the core function you are trying to get working.

The most incredible benefit of using Conveyor is that you even get a public URL that you can use, this is really cool! You can then ask any friend or any remote person to quickly "check something out" while you are working on it.

The second benefit, it is just as simple to get working.

Lastly it is a Visual Studio extension that you install into Visual Studio, so you don't need Node.js / npm. And it simply work with any project you work on, its always there.

Upvotes: 0

s k
s k

Reputation: 5192

I used nginx with the following configuration and it works

    location / {
        proxy_pass  http://localhost:<your port>/;
        expires -1;
    }

I was informed that ngrok works as well, but it kept on deleted by Microsoft Defender after download, because of Trojan.

Upvotes: 0

Smileyfox
Smileyfox

Reputation: 126

What helped me in my dotnet core 6 project to allow remote access to my IIS server is to set up the project's "applicationUrl" parameter in [solution directory]/Properties/launchSettings.json changing the value from "http://localhost:5000" to "http://0.0.0.0:5000"

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:20845",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyLittleProject": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "applicationUrl": "http://0.0.0.0:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

But it's also important to set up a firewall properly to allow access to server's TCP port: in my case an inbound rule for TCP port 5000 to allow connections was added.

Upvotes: 0

Daniel Eisenreich
Daniel Eisenreich

Reputation: 1523

If you're working with Visual Studio then follow these steps to access the IIS-Express over IP-Adress:

  1. Get your host IP-Adress: ipconfig in Windows Command Line

  2. GoTo

    $(SolutionDir)\.vs\config\applicationHost.config
    
  3. Find

    <site name="WebApplication3" id="2">
       <application path="/" applicationPool="Clr4IntegratedAppPool">
          <virtualDirectory path="/" physicalPath="C:\Users\user.name\Source\Repos\protoype-one\WebApplication3" />
       </application>
       <bindings>
         <binding protocol="http" bindingInformation="*:62549:localhost" />
       </bindings>
    </site>
    
  4. Add: <binding protocol="http" bindingInformation="*:62549:192.168.178.108"/>
    with your IP-Adress

  5. Run your Visual Studio with Administrator rights and everything should work

  6. See post from Andrii how to configure Firewall: here

Upvotes: 55

MelOS
MelOS

Reputation: 653

Combining answers in this thread, this is how I fixed it(Visual Studio 2019):

  1. Start Visual Studio as an Administrator and Run your Web Service as you normally do.

  2. Find IIS Express icon on the taskbar, right click on it then click "Show All Applications".

  3. Select your Web Service and note the config path displayed below. Click on the config file to open it for editing.

  4. Find your web service(example search for your port) in this config file then find a line like this: *:yourport:localhost

  5. Add a new line after that like this:

    :yourport:*

In this case no need to create bindings with specific ip address which could change in the future.

I hope this helps someone out there.

Upvotes: 17

Haryono
Haryono

Reputation: 2812

For me using this, relatively simple, and straight forward:

Download the Visual Studio Extension by searching for 'Conveyor' in the Extensions dialog. Then just install.

form: https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

Upvotes: 1

Pasindu Jay
Pasindu Jay

Reputation: 4510

Another way to access external requests is to use IIS instead of IIS Express. In my visual studio, I can just switch easily.

enter image description here

Upvotes: 3

Maksym Labutin
Maksym Labutin

Reputation: 571

I did all of these steps and nothing helped me. And what I need, it's just to run my app via IIS Express...

enter image description here

Hope it helps.

Upvotes: 1

Toolkit
Toolkit

Reputation: 11119

Nothing worked for me until I found iisexpress-proxy.

Open command prompt as administrator, then run

npm install -g iisexpress-proxy

then

iisexpress-proxy 51123 to 81

assuming your Visual Studio project opens on localhost:51123 and you want to access on external IP address x.x.x.x:81

Edit: I am currently using ngrok

Upvotes: 179

Artur Kedzior
Artur Kedzior

Reputation: 4263

The simplest and the coolest way I found was to use (it takes 2 minutes to setup):

https://ngrok.com/

It will work with anything running on localhost. Just signup, run little excutable and whatever you run on localhost gets public URL you can access from anywhere.

This is good for showing stuff to your remote team mates, no fiddling with IIS setup or firewalls. Want to stop access just terminate executable.

ngrok authtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

ngrok http -host-header=localhost 89230

assuming that 89230 is your IIS Express port

You can also run multiple ports even on free plan

Upvotes: 10

Paul Franke
Paul Franke

Reputation: 1

[project properties dialog]

For development using VisualStudio 2017 and a NetCore API-project:

1) In Cmd-Box: ipconfig /all to determine IP-address

2a) Enter the retrieved IP-address in Project properties-> Debug Tab

2b) Select a Port and attach that to the IP-address from step 2a.

3) Add an allow rule in the firewall to allow incoming TCP-traffic on the selected Port (my firewall triggered with a dialog: "Block or add rule to firewall"). Add will in that case do the trick.

Disadvantage of the solution above:

1) If you use a dynamic IP-address you need to redo the steps above in case another IP-address has been assigned.

2) You server has now an open Port which you might forget, but this open port remains an invitation for unwanted guests.

Upvotes: -1

Ronny Mor&#225;n
Ronny Mor&#225;n

Reputation: 567

I solved it with the installation of "Conveyor by Keyoti" in Visual Studio Professional 2015. Conveyor generate a REMOTE address (your IP) with a port (45455) that enable external request. Example:

enter image description here

Conveyor allows you test web applications from from external tablets and phones on your network or from Android emulators (without http://10.0.2.2:<hostport>)

The steps are in the following link :

https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

Upvotes: 29

brz
brz

Reputation: 1959

As a sidenote to this:

netsh http add urlacl url=http://vaidesg:8080/ user=everyone

This will only work on English versions of Windows. If you are using a localized version you have to replace "everyone" with something else, for example:

  • "Iedereen" when using a Dutch version
  • "Jeder" when using a German version
  • "Mindenki" when using a Hungarian version

Otherwise you will get an error (Create SDDL failed, Error: 1332)

Upvotes: 37

srmrco
srmrco

Reputation: 156

You may try setting up port forwarding instead of trying to modify your IIS Express config, adding new HTTP.sys rules or running Visual Studio as an Admin.

Basically you need to forward the IP:PORT your website runs at to some other free port on your machine but on the external network adapter, not localhost.

The thing is that IIS Express (at least on Windows 10) binds to [::1]:port meaning it listens on IPv6 port. You need to take this into account.

Here is how I made this work - http://programmingflow.com/2017/02/25/iis-express-on-external-ip.html

Hope it helps.

Upvotes: 5

konzo
konzo

Reputation: 2093

I had a local IIS enabled so i just created a rewrite rule to my debugging port... I think this is better and cooler than other method because it is easier to remove once am done developing... Here is how the rewrite looks..

<rewrite>
    <rules>
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
            <match url="^dev/(.*)" />
            <action type="Rewrite" url="http://localhost:47039/{R:1}" />
        </rule>
    </rules>
</rewrite>

VS also allows you to develop using your local IIS directly (which then allows remote connections) but in turn you must always run it as an administrator... I dont like that.

Upvotes: 4

XperiAndri
XperiAndri

Reputation: 1208

If you run Visual Studio from Admin you can add just

<binding protocol="http" bindingInformation="*:8080:*" />

or

<binding protocol="https" bindingInformation="*:8443:*" />

into

%userprofile%\My Documents\IISExpress\config\applicationhost.config

Upvotes: 3

Ogglas
Ogglas

Reputation: 69918

This is what I did for Windows 10 with Visual Studio 2015 to enable remote access, both with http and https:

First step is to bind your application to your internal IP address. Run cmd -> ipconfig to get the address. Open the file /{project folder}/.vs/config/applicationhost.config and scroll down until you find something like this:

<site name="Project.Web" id="2">
    <application path="/">
        <virtualDirectory path="/" physicalPath="C:\Project\Project.Web" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:12345:localhost" />
    </bindings>
</site>

Add two new bindings under bindings. You can use HTTPS as well if you like:

<binding protocol="http" bindingInformation="*:12345:192.168.1.15" />
<binding protocol="https" bindingInformation="*:44300:192.168.1.15" />

Add the following rule to your firewall, open a new cmd prompt as admin and run the following commands:

netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=12345 profile=private remoteip=localsubnet action=allow

netsh advfirewall firewall add rule name="IISExpressWebHttps" dir=in protocol=tcp localport=44300 profile=private remoteip=localsubnet action=allow

Now start Visual Studio as Administrator. Right click the web projects project file and select Properties. Go to the Web tab, and click Create Virtual Directory. If Visual Studio is not run as Administrator this will probably fail. Now everything should work.

enter image description here

Upvotes: 13

Emmanuel
Emmanuel

Reputation: 8622

What helped me, was right clicking the 'IISExpress' icon, 'Show All applications'. Then selecting the website and I saw which aplicationhost.config it uses, and the the correction went perfectly.

IISExpress configuration

Upvotes: 12

mustafacanturk
mustafacanturk

Reputation: 71

I solved this problem by using reverse proxy approach.

I installed wamp server and used simple reverse proxy feature of apache web server.

I added a new port to listen to Apache web server (8081). Then I added proxy configuration as virtualhost for that port.

<VirtualHost *:8081>
ProxyPass / http://localhost:46935/
ProxyPassReverse / http://localhost:46935/
</VirtualHost>

Upvotes: 2

dhakalan
dhakalan

Reputation: 1

I did the following and was able to connect:

1) changed IIS express config binding from local host to '*'

binding protocol="http" bindingInformation="*:8888:*"

2) Defined inbound rule on firewall to allow the particular port for the protocol type: tcp

3) Add the following command to add network configuration for your port: netsh http add urlacl url=http://*:8888/ user=everyone

Upvotes: 0

Colonel Panic
Colonel Panic

Reputation: 137524

There are three changes you might need to make.

  1. Tell IIS Express itself to bind to all ip addresses and hostnames. In your .config file. Typically:
    • VS 2015: $(solutionDir)\.vs\config\applicationhost.config
    • < VS 2015: %userprofile%\My Documents\IISExpress\config\applicationhost.config

Find your site's binding element, and add

    <binding protocol="http" bindingInformation="*:8080:*" />
  1. Setup the bit of Windows called 'http.sys'. As an administrator, run the command:
    netsh http add urlacl url=http://*:8080/ user=everyone

Where everyone is a windows group. Use double quotes for groups with spaces like "Tout le monde".

  1. Allow IIS Express through Windows firewall.

    Start / Windows Firewall with Advanced Security / Inbound Rules / New Rule...

    Program %ProgramFiles%\IIS Express\iisexpress.exe
    OR Port 8080 TCP

Now when you start iisexpress.exe you should see a message such as

Successfully registered URL "http://*:8080/" for site "hello world" application "/"

Upvotes: 389

eselk
eselk

Reputation: 6884

This is insanely awesome and even covers HTTPS with pretty domain names:

http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx

The really awesome parts I couldn't find anywhere else on SO in case the above link ever goes away:

> C:\Program Files (x86)\IIS Express>IisExpressAdminCmd.exe Usage:
> iisexpressadmincmd.exe <command> <parameters> Supported commands:
>       setupFriendlyHostnameUrl -url:<url>
>       deleteFriendlyHostnameUrl -url:<url>
>       setupUrl -url:<url>
>       deleteUrl -url:<url>
>       setupSslUrl -url:<url> -CertHash:<value>
>       setupSslUrl -url:<url> -UseSelfSigned
>       deleteSslUrl -url:<url>
> 
> Examples: 1) Configure "http.sys" and "hosts" file for friendly
> hostname "contoso": iisexpressadmincmd setupFriendlyHostnameUrl
> -url:http://contoso:80/ 2) Remove "http.sys" configuration and "hosts" file entry for the friendly  hostname "contoso": iisexpressadmincmd
> deleteFriendlyHostnameUrl -url:http://contoso:80/

The above utility will register the SSL certificate for you! If you use the -UseSelfSigned option, it's super easy.

If you want to do things the hard way, the non-obvious part is you need to tell HTTP.SYS what certificate to use, like this:

netsh http add sslcert ipport=0.0.0.0:443 appid={214124cd-d05b-4309-9af9-9caa44b2b74a} certhash=YOURCERTHASHHERE

Certhash is the "Thumbprint" you can get from the certificate properties in MMC.

Upvotes: 0

Bruce
Bruce

Reputation: 2196

If you have tried Colonel Panic's answer but doesn't work in Visual Studio, try this:

Append another <binding /> in your IIS Express config

<bindings>
    <binding protocol="http" bindingInformation="*:8080:localhost" />
    <binding protocol="http" bindingInformation="*:8080:hostname" />
</bindings>

Finally, you have to run Visual Studio as Admin

Upvotes: 9

Ionut-Cristian Florescu
Ionut-Cristian Florescu

Reputation: 1864

I remember running into the same problems while trying this workflow a few months ago.

Which is why I wrote a simple proxy utility specifically for this kind of scenario: https://github.com/icflorescu/iisexpress-proxy.

Using the IIS Express Proxy, it all becomes quite simple – no need to “netsh http add urlacl url=vaidesg:8080/ user=everyone” or to mess up with your “applicationhost.config”.

Just issue this in command prompt:

iisexpress-proxy 8080 to 3000

…and then you can point your remote devices to http://vaidesg:3000.

Most of the times simpler IS better.

Upvotes: 148

Terry Kernan
Terry Kernan

Reputation: 806

I was unable to serve iis requests to other users in my local network, all I had to do (in addition to the above) was restart my BT Hub router.

Upvotes: 0

Robson Douglas
Robson Douglas

Reputation: 101

I have some problems using IIS Express in Win 8.1 and external request.

I follow this steps to debug the external request:

  1. Install IIS
  2. Configure Visual Studio to use local IIS (Page properties in your Web Project)
  3. Create a exclusive AppPool in IIS to work with my application
  4. In my Project I'm using Oracle Client and must be 32bits (64 bits don't work with Visual Studio) then I need allow 32 bit in Application Pool
  5. Configure the Windows firewall to allow request in port 80 (inbound rules)

It's working!

Upvotes: 3

Damian Edwards
Damian Edwards

Reputation: 7339

There's a blog post up on the IIS team site now explaining how to enable remote connections on IIS Express. Here is the pertinent part of that post summarized:

On Vista and Win7, run the following command from an administrative prompt:

netsh http add urlacl url=http://vaidesg:8080/ user=everyone

For XP, first install Windows XP Service Pack 2 Support Tools. Then run the following command from an administrative prompt:

httpcfg set urlacl /u http://vaidesg1:8080/ /a D:(A;;GX;;;WD)

Upvotes: 420

user87453
user87453

Reputation:

A good resource is Working with SSL at Development Time is easier with IISExpress by Scott Hanselman.

What you're after is the section Getting IIS Express to serve externally over Port 80

Upvotes: 31

Chad
Chad

Reputation: 2456

The accepted answer to this question is a guide for getting IIS Express to work with webmatrix. I found this guide more useful when trying to get it to work with VS 2010.

I just followed steps 3 & 4 (running IIS Express as administrator) and had to temporarily disable my firewall to get it working.

Upvotes: 5

Related Questions