I'm trying to configure a new ASP.NET MVC3 using IIS7 express (on my local development machine) to use a custom domain name.
eg.
I've hacked my hosts file to include (yes, i saved the file .. which also meant i had to have admin rights enabled ...
127.0.0.1 dev.www.mydomain.com
I just can't figure out how to use IIS7 express to get configured to do this.
I went to MVC Project => Properties => Web
and did the following :-
Then tried to run the site...
Can anyone help?
Yes, IIS Express uses the same applicationhost. config and web. config files supported by IIS.
Setting Up Host Headers in IIS 7 Using the Command LineInstall the SSL Certificate to the site where you will use secure bindings. Next, open a command line by clicking Start > Run. Type cmd and click OK. Type cd C:\Windows\System32\Inetsrv\ to change the directory where you manage SSL host headers and click enter.
The Host request header specifies the host and port number of the server to which the request is being sent. If no port is included, the default port for the service requested is implied (e.g., 443 for an HTTPS URL, and 80 for an HTTP URL). A Host header field must be sent in all HTTP/1.1 request messages.
Stop currently running site if it is running
Open %userprofile%\documents\iisexpress\config\applicationhost.config
for VS2015+ :$(solutionDir)\.vs\config\applicationhost.config
Locate the site you are interested in and it would have a binding like
<binding protocol="http" bindingInformation="*:<your-port-number>:localhost" />
Now add a similar entry <binding protocol="http" bindingInformation="*:<your-port>:dev.www.mydomain.com" />
just below the above bindig entry.
run the site again
NOTE: You must start visual studio as administrator because non-localhost binding requires administrator privileges
Further to this, we need to do the following. These comments are in the top of my web.config (along with a few other stuff...).
1) netsh http add urlacl url=http://localhost.www.foo.com:80/ user=everyone
netsh http add urlacl url=http://localhost.foo.com:80/ user=everyone
netsh http add urlacl url=http://localhost.foobar.com.au:80/ user=everyone
netsh http add urlacl url=http://localhost.pewpew.com:80/ user=everyone
... etc ...
NOTE: to remove a urlacl: netsh http delete urlacl url=<url in here> .. eg http://foo.com:80
2) ... and we need to edit the main IIS7 express config file to define the url's which will be accepted, per web -site-
File: C:\Users\<UserName>\Documents\IISExpress\config\applicationhost.config
<bindings>
<binding protocol="http" bindingInformation="*:1200:localhost" />
<binding protocol="http" bindingInformation="*:80:localhost.www.foo.com" />
<binding protocol="http" bindingInformation="*:80:localhost.foo.com" />
<binding protocol="http" bindingInformation="*:80:localhost.foobar.com.au" />
<binding protocol="http" bindingInformation="*:80:localhost.pewpew.com" />
</bindings>
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