Skip to content

Instantly share code, notes, and snippets.

@nsbingham
Last active December 18, 2020 20:29
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save nsbingham/9548754 to your computer and use it in GitHub Desktop.
Save nsbingham/9548754 to your computer and use it in GitHub Desktop.
How to get ngrok working with IISExpress/Visual Studio 2013
  1. Decide on a subdomain to use with ngrok. This makes the whole process easier.
  2. Open up a Command Prompt in Administrator mode and run the following command to register the URL with HTTP.sys replacing "modernie" with your subdomain and ##### with your VisualStudio/IISExpress application's port.
netsh add urlacl url=http://modernie.ngrok.com:##### user=everyone
  1. Edit your applicationhost.config. The easiest way to is start up the site and right-click the IISExpress icon in the System Tray. Click "Show All Applications" and select your website running at localhost:#####. Click the path next to "Config" to open the file in an editor.
  2. Search for you site's <bindings> configuration. The easiest way is to search for *:#####:localhost, which should bring you to the <bindings> section for your site. Edit them to include the following:
<bindings>
  <binding protocol="http" bindingInformation="*:#####:modernie.ngrok.com" />
  <binding protocol="http" bindingInformation="*:#####:localhost" />
</bindings>

Save the file, making sure to replace "modernie" with your subdomain and ##### with your application's VisualStudio/IISExpress port.

  1. Restart your site.
  2. Run ngrok with the subdomain settings from a Command Prompt running in Administrator mode. This can be done with the following command:
ngrok.exe -authtoken XXXXXXXXXXXXXXXXXXXX -subdomain=modernie #####

Make sure to replace "modernie" with your subdomain and ##### with your application's VisualStudio/IISExpress port.

@inconshreveable
Copy link

@nsbingham would you mind if I included these instructions as part of ngrok's official documentation?

@nsbingham
Copy link
Author

@inconshreveable glad you find it helpful! Feel free to include in ngrok's official documentation. ngrok is a great tool!

@danbramall
Copy link

Should the first command line snippet be like this? (i.e. Missing 'http' after 'netsh' and trailing slash after port number)

netsh http add urlacl url=http://modernie.ngrok.com:#####/ user=everyone

@IDisposable
Copy link

Dan's command is what works in Windows 8.1

@hawaiikaos
Copy link

I'm trying to get this to work with a site name that's not "localhost", but using port 80. My binding info line is:

<binding protocol="http" bindingInformation="*:80:whatever.local.com" />

whatever.local.com is correctly added to the etc/hosts file and it the local site is viewable at whatever.local.com. I've tried running ngrok like so:

ngrok http whatever.local.com:80

But when I go to the url ngrok provides, I get a 404 error (and the tunnel clearly works). When I add the following to applicationHosts.config file:

<binding protocol="http" bindingInformation="*:80:urlfromngrok.ngrok.io" />

and restart the server, there is no change; I still get the 404.

I have also added the url with netsh as above. No dice.

I have no idea how to proceed, as I'm not sure where the issue lies. Clearly something is being served, it's just not the right something. If anyone has any insight, I would be very grateful. Ngrok is so blissfully easy to use on Mac/*nix, but IIS just makes me want to huck my machine out my 5th story window.

@hawaiikaos
Copy link

Okay I have a solution to the above. Ngrok needs to be invoked thusly:

ngrok http -host-header=rewrite whatever.local.com:80

I also allowed external traffic to the hostname (but this may have been incidental to the solution):

netsh http add urlacl url=http://whatever.local.com:80/ user=everyone

No messing with the ApplicationHost.config file was necessary.

@vivan-snapretail
Copy link

has anyone been able to get ngrok working with IIS express over https?

@moranm6
Copy link

moranm6 commented Jan 5, 2016

Is there any way to do this without being able to set a subdomain? I am trying the free version and cannot set a subdomain so restarting in step 5 changes my url.

@dmarkrollins
Copy link

@hawaiikaos

This worked for me - thanks

ngrok http -host-header=rewrite whatever.local.com:80

@dprothero
Copy link

This is much easier now with just this single command:

ngrok http -subdomain=modernie -host-header="localhost:#####" #####

No need to run netsh or edit the IIS Express config file.

@ProNotion
Copy link

@dprothero you are a lifesaver! I've been struggling this for a really long time and glad you posted a working solution. When I first started using ngrok a few years back I had an equally tough time getting up and running with IIS Express and ended up using the following which no longer works:

ngrok http 192.168.0.x:xxxx -subdomain=mysubdomain

@dprothero
Copy link

@ProNotion and everyone, I built a Visual Studio extension to make this easier. Please let me know what you think:
https://visualstudiogallery.msdn.microsoft.com/56a642ed-a5e0-4044-8735-740d36912c5e

@RefractedPaladin
Copy link

@moranm6 did you ever solve this? I also need this solution so I can convince "management" to pay for this tool.

@ProNotion
Copy link

@dprothero It works a treat - thanks so much for taking the time and for sharing. I'm still curious - why I can't get it work from the command line myself anymore but thanks for a great extension!

@tscbp
Copy link

tscbp commented Sep 12, 2018

Tried dprothero's command above, as well as the extension. Tried netsh and editing applicationhost.config. In every case, what I get when I try to visit the ngrok url is:

a) in my ngrok client, I see the request come in - so it is getting to my machine
b) the request takes quite a while - ballpark 2 minutes?
c) eventually comes back 502

seemingly same as this StackOverflow article

Anyone else running into this with VS2017?

@BitWizJason
Copy link

@tscbp The latest version of ngrok resolves the issue see inconshreveable/ngrok#448 and my answer at the SO article you mentioned: VS 2017 IIExpress ngrok SO Article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment