Test multiple domains using ASP.NET development server - asp.net

I am developing a single web application that will dynamically change its content depending on which domain name is used to reach the site. Multiple domains will point to the same application. I wish to use the following code (or something close) to detect the domain name and perform the customizations:
string theDomainName = Request.Url.Host;
switch (theDomainName)
{
case "www.clientone.com":
// do stuff
break;
case "www.clienttwo.com":
// do other stuff
break;
}
I would like to test the functionality of the above using the ASP.NET development server. I created mappings in the local HOSTS file to map www.clientone.com to 127.0.0.1, and www.clienttwo.com to 127.0.0.1. I then browse to the application with the browser using www.clinetone.com (etc).
When I try to test this code using the ASP.net development server the URL always says localhost. It does NOT capture the host entered in the browser, only localhost.
Is there a way to test the URL detection functionality using the development server?
Thanks.

Figured this one out on my own. The problem here wasn't that the HOSTS file didn't work, it was that I was using the wrong method to detect the host header from the browser.
This does NOT work, and only repeats the 127.0.0.1 localhost that the ASP development server lives on.
Request.Url.Host;
However, by using the following instead, the domain entered into the browser is stored and can be used to dynamically change the site behavior, even on the ASP development server.
HttpContext.Current.Request.Headers.Get("Host").ToString();
So the solution to test multiple domains on a Dev server is:
create several test domains in the HOSTS file on your local machine pointing to 127.0.0.1
use the Headers.Get("Host") syntax to sniff the domain entered into the browser
The only 'gotcha' that I found is that you must still manually preserve the specific port that the ASP dev server is running on.
Example:
if you have in your hosts file www.mytestdomain.com pointing to 127.0.0.1, and your dev server is running on port 46146, then you must enter the following into your browser for testing: http://www.mytestdomain.com:46146/
But it still works!

Related

Url rewriting with Charles Proxy in order to run a wordpress site over a LAN?

I want to use Charles Proxy to share a local development PC's web server where I am developing sites on so that I can access the PC over my LAN to test on various mobile devices.
Having setup the correct ip address of my PC in the http proxy settings on various tablets they can all connect to the PC and this works fine.
The issue is that I need to test a wordpress site and as anyone that uses wordpress knows, it generates full url links between each page it serves. As the site normally runs on my PC the urls it generates are all http://localhost/wordpress/pagename.
So the issue is that if I access the same site from a remote device via the proxy (addressing http://192.168.1.200/wordpress/) it instantly redirects me to http://localhost/wordpress/pagename url in the mobile device and this fails to load as the tablet can't determine "localhost" correctly.
There must be a way of using one of Charles' various options to resolve this but I can't for the life of me work out which. I've tried remote maps and DNS spoofing but no joy.
Note, I'm completely aware that you can with SQL commands change the urls throughout a wordpress database but I just wanted to see if this was possible without undertaking this step as it would be a lot more flexible if I don't have to do that each time I want to preview sites via my other local LAN devics.
You can use Charles proxy feature called Rewrite Tool. I assume your local network uses 192.168.168.X IPs.
Enable rewrite
Add new rule and name it as you wish
To Locations section add Protocol: http and Host: 192.168.168.X
To Rules section add Type: body, Where: response, Match: localhost, Replace: 192.168.168.X
It may require some more tinkering but i hope you get the idea

Windows Azure VM SSL and Cloudapp.net

I installed an ASP.net application on a windows Azure VM (IIS 7). SSL certificate is installed, configured and the application works correctly. I have removed Http binding and http endpoints.
The issue I am having is that if I use the cloudapp.net link (using https), the application still opens with a mismatched certificate.
What can I do to deny any user from opening my application using https://xx.cloudapp.net/x?
It seems really silly that people are saying this isn't the right place for this question, since some of the solutions could be code related. ie: In your application, check the host and if it's cloudapp.net, do a URL redirect.
There's a few different options here but it sounds like what you're looking for is just the ability to prevent someone from viewing the application using that URL.
What I would do is set up a site in IIS that uses Host Header resolution to look for xx.cloudapp.net. If that URL is recognized, do a redirect using the HTTP redirect settings to the https version of your app. Don't bind the SSL port to this site or you'll run into SSL errors like you showed above.
The other option is to leave it out entirely and simply use the Host Header resolution to filter out requests for your site. I suspect what you've done is assign all incoming requests to the only IP address on the system, which is why the xx.cloudapp.net is showing your app and the cert is failing.
This would cause xx.cloudapp.net to fail to show any site at all but I think that might be what you want to do anyway.

How do I give access to another computer on my network, to my website hosted locally?

We have a local instance of IIS 7 running with a website. Instead of the default "localhost" we have something like, mysite.compname.com. This is a separate entry into IIS 7 and the default website was removed to prevent confusion.
Then in our host file we an entry like this:
127.0.0.1 mysite.compname.com
Now when I try to hit this url, http://127.0.0.1/ApplicationName/Project/AddProject.aspx technically it should work, but instead I get a 404. I can vouch that this isn't a problem with the application, because if I navigate to http://mysite.compname.com/ApplicationName/Project/AddProject.aspx it works fine.
My end goal is to be able to give someone my computer name, so that they can visit a test page, so the url above I think would get turned into this http://computername/ApplicationName/Project/AddProject.aspx. Any help or at least links to understanding would help because I'm not sure where my issue is coming from.
It sounds like the IIS site / application is configured using a Host Header.
This means that the site will only respond if the host header sent by the browser matches the one configured for the site.
This is a standard method to allow one server to host sites for many host and domain names.
If you wish to allow others to view the site on your computer you will need to either have a local DNS server which you can edit, or, probably the easiest option, get them to edit their host files to include
<your IP> mysite.compname.com.
Remember to open the requisite ports (probably only 80, maybe 443 for https) in your firewall.
Or, you can try to edit the site config to remove or modify the Host Header requirement. See the first link for details, but be careful, it's easy to break things if you don't know the entire architecture of the site.

IIS website inaccessible from server (but ok from outside)

On a server where an IIS website is hosted, if I open IE or Firefox and type the IIS website url, i got an error after a few seconds ("Cannot display the webpage", just like website would be offline). If I do the same from the exterior (as normal user do) everything works.
I have tried to give the IP address directly (thus skipping DNS), problem is the same. It only works if I type the internal ip address of the IIS website (eg : 10.0.0.x).
The reason I want to do that is that I need to access a specific page of the website in order to execute a scheduled task. I cannot use internal ip address to do that, because host name (HttpContext.Current.Request.Url.Host) is used inside ASP.NET code to switch between different configuration.
Here is my question : is it possible to access a specific page on a IIS website from server where website is hosted ? (using complete url, not internal ip address ?)
Yes - If I understand your question correctly you should be able to add a mapping in your local hosts file to point that domain at your IIS webserver.
e.g.
10.0.0.x my.example.hostname
(where x is obviously a number)
We use this configuation internally when developing multiple sites on our local machines - each site is bound to a specific hostname and all these hostnames have mappings in the 'hosts' file to 127.0.0.1
The same principal applies here, if I've understood the question correctly :)

Getting site running in IIS 7 Issues

This is driving me nuts. I am trying to setup a webiste on our dev server with a specific url name www.mystpidsite.com as an example. mystupidsite is not the same name as the dev server.
1) specify a specific url to use for the website I create in IIS
2) run it and use that url to access it
I have:
1) created a new site in IIS 7 in Server 2008
2) attempted to access it via the site name which I set to the desired url and port 8888. So if we want it to be www.mystupidsite.com I setup the website name to mystupidsite in IIS 7.
3) I even tried to create an application under mystupidsite with the same name in IIS 7.
The server is definitely accessible and pingable on the network from my local PC, we have other stuff installed on this new server. Do I need to create an application or is just creating the website enough in IIS 7? I specified the IP as the server's IP in the website I made.
For the host name in the bindings of the site I put www.mystupidsite.com
when I try to access the site via www.mystupidsite.com it can't find it and the site in IIS7 on the dev server is running. It's running on a HyperV instance which is our dev server. Everything else has worked just fine. I just wnat to understand how to get a specific url by name setup.
Do I need to add something in the hosts file on the server or something?
You're not going to be able to have a site on your dev box answer to both the mystpidsite.com and mystupidsite.com domain names.
Unless you have the domains registered and have your domain's nameserver directing that name to your dev machine, IIS is only going to answer to requests either the machine name on the network or the IP address of your machine (in addition to 127.0.0.1 and localhost).
The only thing you're going to be able to do outside that scenario is set up two sites on two different ports on your machine and access them from http://localhost:80 and http://localhost:8888 (or network computer name equivalent).
you need to have an entry in dns to be able to hit the server when using www.mystupidsite.com
Because you have the site running on an alternate port you should be able to get to it by http://your-server-IP-address:8888
If you want to test it locally using the host name and do not have access to dns you can add the appropriate entries to the hosts file on your local machine (c:\windows\system 32\drivers\etc\hosts)
What happens when you type 'nslookup www.mystupidsite.com'? Do you get the IP address of the virtual server?
Do you have the windows firewall enabled on the server? if so, did you add an exception for port 8888?
add a default binding (no host header / blank) and try accessing it by IP

Resources