allow prefix before localhost domain name in IIS express - visual-studio-2013

I'm building a MVC web application that should respond to domains like a.sub.example.com, b.sub.example.com, c.sub.example.com etc. I'm ok figuring out how to get out the a,b,c etc prefix and create a proper route accordingly, but I'm struggling to get the IIS webserver to actually forward the requests to the same webapplication.
I followed this guide to make IIS express listen to another address, in this case sub.example.com, which works fine. However, I cannot figure out how to get it to listen to all subdomains of that one. When I direct my browser to a.sub.example.com, I get an error:
HTTP Error 400. The request hostname is invalid.
I added both sub.example.com and a.sub.example.com as aliases for 127.0.0.1 in my hosts file.
My applicationhost.config file's 'site' entry looks like this:
<site name="MyProject.Web" id="7">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="..." />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8888:sub.example.com" />
</bindings>
<applicationDefaults applicationPool="Clr2IntegratedAppPool" />
</site>
When I replace the 'bindingInformation attribute with
"*:8888:*.sub.example.com"
as the previously mentioned guide suggests I should do when I want IIS express to listen to multiple domains, IIS Express fails to start at all.
Am I missing something obvious here?

The way i know of is to set the IIS applicationhost.config (Full path: %UserProfile%\Documents\IISExpress\config\applicationhost.config) and find the referance to the port number.
<site name="WebSite1" id="1">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%WebSite1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":49483:localhost" />
</bindings>
</site>
i normaly add <binding protocol="http" bindingInformation=":49483:" /> to accept all hosts on that port (note empty string, not wildcard *).
You will have to have set up this host to point to 127.0.0.1 in your hosts file. Or, use a domain you own and point .sub.mydomain to 127.0.0.1. Hosts file doesn’t support wildcards () but DNS does! This means I can easily set up myproject.sub.mydomain and myproject.sub.mydomain without having to add new lines to my hosts file (so long as I have an internet connection)!
Hope this helps

Related

Virtual Directory Not working in local IIS

I have a virtual directory set up in local IIS to serve up images but when the web page runs it gives a 404 for the images and shows that it is looking at the physical path for the website not the path specified for the virtual directory
I have things set like this:
IIS7.5
Site is MyWebSite
physical path is c:\mywebsite
virtual directory for MyWebSite\images has physical path c:\myimages
I can see everything including files in the virtual directory
Binding
http 127.0.0.1 port 80 (also tried port 59925)
host header is MyWebSite
Visual Studio
Properties>Web set to run in local IIS
project url is set to: http://localhost/mywebsite
Windows host file the last line is
127.0.0.1 localhost
I also tried
127.0.0.1 localhost/mywebsite
127.0.0.1 mywebsite
I run the site from visual studio and it runs fine except for the images. Clicking on the link in page source opens an error page with a 404 error. The physical path shown is c:mywebsite instead of c:\myimages.
I am assuming something is wrong with something in the setup above but not sure what it is.
Edit
the url in the page source is a relative one
img src=../../myimages/myimage.jpg
Requested URL http://localhost:80/mywebsite/mymages/image.jpg
Physical Path C:\MyWebSite\myimages\image.jpg
**Edit 2 ** here are the site bindings
<sites>
<site name="Default Web Site" id="1">
<application path="/">
<virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
</application>
<application path="/WebSiteManager2019" applicationPool="DefaultAppPool">
<virtualDirectory path="/" physicalPath="C:\MyWebSite" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
<site name="MyWebSite" id="3" serverAutoStart="true">
<application path="/" applicationPool="MyWebSite">
<virtualDirectory path="/" physicalPath="C:\MyWebSite" />
<virtualDirectory path="/images" physicalPath="C:\MyImages" />
</application>
<bindings>
<binding protocol="http" bindingInformation="127.0.0.1:80:MyWebSite" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%SystemDrive%\inetpub\logs\LogFiles" />
<traceFailedRequestsLogging directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" />
</siteDefaults>
<applicationDefaults applicationPool="DefaultAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>

Using SSL with IIS Express

I am trying to run my VS project on localhost using a fake domain (bobby.fisher.com). To do this I created a virtual directory in the applicationhost.config file as follows:
<site name="Tidywork.Integrations.Web" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\bobbyfisher\Workspaces\bobbyfisher.Integrations\bobbyfisher.Integrations\bobbyfisher.Integrations.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:35464:localhost" />
<binding protocol="http" bindingInformation="*:80:bobby.fisher.com" />
<binding protocol="https" bindingInformation="*:44321:localhost" />
<binding protocol="https" bindingInformation="*:44321:bobby.fisher.com" />
</bindings>
</site>
However, when I tried run the program (https://bobby.fisher.com/) I ended up with an error:
This site can’t be reached
bobby.fisher.com refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
Does anyone have any suggestions how to do this?
If you don't specify a port in your URL when accessing the site, then if you chose https:// (as per your example) the browser will try to connect on port 443 automatically - because that's the standard port for HTTPS.
But you haven't configured that port in your IIS settings. So either bind that port to https for your application, or use a port number explicitly in your URL (e.g. https://bobby.fisher.com:44321)

Why would I get a "503 - Service Unavailable" error when the service is available?

According to this, a 503 error is "503 Service Unavailable
The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state."
Yet that doesn't seem to be the case for me. I have a Web API server app running which exposes a REST method. I can successfully call it from Fiddler Composer (it receives a file and saves it to disk), but ONLY if I use "localhost" (the IP Address doesn't work, nor does the Hostname).
When trying to call the method from my Windows CE / Compact Framework handheld device (which cannot use "localhost" as that would be narcissistic and foolhardy), I can get either error 400 - Bad Request from the server, or the 503 error, depending on whether I use the IP address or the Hostname of the PC on which the Web API app is running.
With my applicationhost.config file like this:
<site name="HHS.Web" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\project\git\CStore\HHS.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:21608:localhost" />
<binding protocol="http" bindingInformation="*:21608:192.168.125.50" />
</bindings>
</site>
...I get err 400 - Bad Request when I try to call a REST method on HHS.WEB from a handheld client using this URL: http://192.168.125.50:21608/api/inventory/sendXML/duckbilled/platypus/bla
With applicationhost.config file like this:
<site name="HHS.Web" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\project\git\CStore\HHS.Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:21608:localhost" />
<binding protocol="http" bindingInformation="*:21608:shannon2" />
</bindings>
</site>
...and this uri, using my hostname: http://shannon2:21608/api/inventory/sendXML/duckbilled/platypus/bla
...I get the "503" error. The server is running, as can be seen when I change the entry in applicationhost.config and the URL that I call; so why is it telling me it's not available?
UPDATE
I was hoping I had had a brainstorm, and that using "PPP_PEER" to designate the PC would do the trick, and so I changed the URL the app on the handheld device is calling from this:
http://192.168.125.50:21608/api/inventory/sendXML/duckbilled/platypus/bla
...to this:
http://PPP_PEER:21608/api/inventory/sendXML/duckbilled/platypus/bla
...as that seems to be how the handheld must reference the PC, but that just takes me back to the "400 - Bad Request" err msg (and the breakpoint in the server app is still not hit). If using "PPP_PEER" is the right idea, what else do I need to make it work?
UPDATE 2
The crux of the biscuit was adding at the command prompt either this:
netsh http add urlacl url=http://shannon2:80/ user=everyone
...or this:
netsh http add urlacl url=http://shannon2:8080/ user=everyone
See Update 5 here for more details

IIS Express ApplicationHost config file partially ignored when setting remote access

I modified the default application host file to enable remote connection to my IISExpress. As I learned here, I modified the bindings as follows:
<sites>
<site name="Development Web Site" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_BIN%\AppServer\empty_wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:*" />
</bindings>
</site>
<sites>
When starting the service, I get this:
C:\Program Files\IIS Express>iisexpress /path:c:\iis\ /port:80
Copied template config file
'C:\Program Files\IIS Express\AppServer\applicationhost.config'
to 'C:\DOCUME~1\test\LOCALS~1\Temp\iisexpress\applicationhost201311513534137.config'
Updated configuration file 'C:\DOCUME~1\test\LOCALS~1\Temp\iisexpress\applicationhost201311513534137.config' with given cmd line info.
Starting IIS Express ...
Successfully registered URL "http://localhost:80/" for site "Development Web Site" application "/"
Registration completed IIS Express is running. Enter 'Q' to stop IIS Express
And in the actual config file I have this:
<site name="Development Web Site" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="c:\iis\" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:localhost" />
</bindings>
</site>
As the server is bound to localhost, I can't access it remotely.
How can I force the setting to take effect?
Solution: use the /config switch and assign a specific config file so it won't copy the default file and doesn't modify it uncontrollably.

IIS express 7.5 only loading one site even though 2 sites defined?

I have IIS express loaded and running from a command line entry. I am using the default applicationhost.config file (I know it's the correct file as I have changed the 1st site's port a couple of times etc).
The strange thing is, I have two sites defined, and it appears only the first one gets loaded? I am sure IIS express can load multiple sites right? as long as different ports?
Here is the <sites> definition bit from the applicationhost.config file:
<sites>
<site name="BF Local SVN" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\_CODE SOURCECONTROL\BizzfaceLocalSVN" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:6464:localhost" />
</bindings>
</site>
<site name="SquirrelITfreeformBS" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\_CODE SOURCECONTROL\SquirrelITfreeformBS" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:6465:localhost" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
As you can see, two sites defined, different site ID's and different ports?
Any ideas?
When you run iisexpress.exe from command line (without any command line arguments), it starts the first site given in default applicationhost.config file (%userprofile%\documents\iisexpress\config\applicationhost.config).
To start multiple sites, use /apppool switch as shown below;
iisexpress.exe /apppool:Clr4IntegratedAppPool
Above command would start all the applications that are using 'Clr4IntegratedAppPool' app pool.

Resources