I have a multi-tenant application that is accessed in production as customer.ourdomain.com
. For local development with IIS, we use a custom wildcard domain, company-localdev.com
.
With IIS, this works without any particular configuration. IIS Express, on the other hand, only binds to localhost
.
We have an ongoing migration project to ASP.NET 5, and we'd like to use IIS Express for an easier developer experience.
Is it possible to have IIS Express listen to *.company-localdev.com:1234
? Bonus points if this can be automated so a developer can have it working just by opening the solution in IIS.
I had this exact same issue with IIS Express in Visual Studio 2019. MSDN held the answer.
The value of this property is a colon-delimited string that includes the IP address, port, and host name of the binding. You can leave the host name blank.
This simple binding will accept all hostnames
<bindings>
<binding protocol="http" bindingInformation="*:1234:" />
</bindings>
In ASP.NET 5 / vNext, the config file is found in
~ProjectFolder~/.vs/config/applicationhost.config
From there, you can add new bindings like rdans explained.
Ok I got it working on my local machine, here are all the steps I had to take:
Go to {YourProjectFolder}\.vs\config
and edit the
applicationhost.config file:
<site name="MySite" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="{MyProjectFolderPath}" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:49861:localhost" />
<binding protocol="http" bindingInformation="*:80:example.com" />
<!-- for subdomain testing only -->
<binding protocol="http" bindingInformation="*:80:sub1.example.com" />
<binding protocol="http" bindingInformation="*:80:sub2.example.com" />
</bindings>
</site>
Run Notepad as Administrator and go to C:\Windows\System32\drivers\etc
to open the hosts file and amend it like so
127.0.0.1 example.com
127.0.0.1 sub1.example.com
127.0.0.1 sub2.example.com
Add the url reservation by running cmd.exe as Administrator and typing in the netsh http prompt (to get the netsh http>
prompt, you must type netsh
followed by Enter, then http
followed by Enter
):
add urlacl url=http://example.com:80/ user=everyone
add urlacl url=http://sub1.example.com:80/ user=everyone
add urlacl url=http://sub2.example.com:80/ user=everyone
Bear in mind that the keyword everyone
depends on the language of your Windows OS. On a French OS, user=everyone
shall be replaced by user="Tout le monde"
, on a German OS it should be user=jeder
, in Spanish user=todos
etc... you get the idea.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With