Test subdomains on local webserver in VS - c#

I am still experimenting with Azure multi tenant development. I now have my first trial thingy, but in order to use subdomain names (customer.site.com) I need to switch my Azure website to shared/reserved. Since I am still experimenting, I rather not start paying for Azure. Is there a way around this? Or, is it possible to test the multi-tenant part in my local visual studio webserver?

No, you can't have custom domain names with FREE websites.
But what you could do, is to switch the tenant recognition from sub-domain to a path. So instead of having tenant10.site.com/ you would have mysites.azurewebsites.net/tenant10/. That would basically be just a change in URL Rewrite rules - which I think is the right way to handle multi-tenancy recognition at URL level. And URL rewrite is supported in Azure WebSites as well Azure Cloud Services.
Testing the multi-tenancy locally is even easier. You just open your hosts file (in a typical windows installation it is located in c:\windows\system32\drivers\etc\hosts. Just add entries for all (sub)domains you want to test, and map them to 127.0.0.1. Something like:
127.0.0.1 tenant1.mydomain.com
127.0.0.1 tenant2.mydomain.com
127.0.0.1 tenant15.mydomain.com
...
Then, run your project with F5 like you would normally do and manually type in the new address in browser's address bar: tenant1.mydomain.com.
However first launch the project with F5 to check the real IP address of local development fabric, because sometimes it may not be 127.0.0.1, but 127.0.0.8 or something else. The IP address that is used in your browser's initial launch is the IP Address you have to fill in your hosts file.
However, if you work with real (sub)domain names in hosts file, do never forget to remove the entries from it, as you will never reach the real Internet sites.

Related

Deploy a callback API to a VM with IIS

I am hoping to deploy a web api to handle callbacks from a 3rd party.
I'm a beginner at C#, but I've written a simple Web API using Visual Studio in order to handle the callbacks.
To test on my dev machine I click the green run button with IIS selected on localhost, and the dll is created. I can feed it some 3rd party test JSON files (using Postman) and the database is updating correctly. So far so good.
Now I'm looking at deployment to a test server, which can receive live (test) callbacks. To do this, I've run up a new VM with a public IP address, installed SQL Express and also installed IIS.
I am assuming the next step is to publish (web deploy) from VS.
But I'm becoming confused with regard to domain name, URL and IP address.
a) Do I need to register a domain name for the IP address? (There is no UI, just the callback endpoint)
b) When setting up the publishing profile for web deploy, what is the Destination URL?
There is a lot of information available on the subject, but there are clearly a few important gaps in my knowledge, and I can't seem to fill 'em.
Thanks
If I am understanding your question correctly - no you do not need a domain name to test your application. You can use a tool like Swagger to test your API. Read more here: https://www.blazemeter.com/blog/getting-started-with-swagger-ui
Good luck!

Multi-Store development

Currently with my company we are working with a third party software for multi-store fronts (portals) called ZNode. We have a couple portals/stores set up and the web team we have has set up the portals to use different headers/footers/navigation. The url's for the stores are different in our dev environment (store1.com/shoppingcart.aspx vs store2.com/shoppingcart.aspx) and they have different views of the same page and follow the same navigation set up by the different buttons within the store.
The problem though is that I need to troubleshoot problems for store2.com/shoppingcart.aspx but when I try to do it on the localhost through visual studio's I move between store1 (the main store) and store2 (the one I need to troubleshoot) and I don't know how to stay on store2's portal because when I run the page/project locally through VS the url is of course a localhost link with a port number so I can't stay on the second portal like I need to. I just move between them when I reach a page that is one portal and not the other. And when I reach a page that is shared (like shoppingcart.aspx) I move onto the main store/portal.
I didn't know if anyone had some insight into how I could possibly stay on one and not move between them, if you do thought I would be very interested to try any ideas anyone might have on how to stay on one portal or the other. I have asked tech support for the third party vendor but have not heard back yet and I would like to get a jump on trying things while I wait for a response that could take, potentially, a few days.
Currently, we have to the localhost dev site set up through IIS to run on a certain port with the authentication of our active directly log in. Don't know if this helps or not.
Sounds like you need to create multiple bindings to the same site in iis in your dev machine. Like store1.com and store2.com. Then map both to your local box in the hosts file (system32/drivers/etc/hosts)
127.0.0.1 store1.com
127.0.0.1 store2.com
This way your local iis will answer to requests to both domains from the same site.

Request.Url.Host vs Request.Url.Authority

I've inherited an ASP.NET web application written in C#. In many pages throughout the site the hostname is retrieved using:
BaseHost = Request.Url.Host;
Since I am using Visual Studio 2012 Express and it's installed local IIS Express server, I seem to be stuck with a port number appended to the hostname (localhost) when I debug/run locally. The above code does not result in the port number being included and as such breaks links that are generated by code (menu item links, redirects, etc).
I see that I can overcome the issue by changing the code to:
BaseHost = Request.Url.Authority;
This seems to fix it by including the port when I'm running locally (localhost:4652) and when published to my staging server (development.mysite.com).
My question: Is this bad form? Is there a time or a situation in which this is going to cause problems on my live site? It just seems a lot easier to do a quick replace of all these instances. I've considered writing a small routine to append : with Request.Url.Port, but it seems easier just to use Request.Url.Authority. Too easy maybe...
I've tried to research my question online and at MSDN, but I don't see an answer.
According to MSDN Authority includes the port number while Host does not. Another aspect is that Authority will escape reserved characters if need be.
Without knowing your application it is hard to say whether it is a good idea, but in general I would suspect that it won't break anything... so go ahead...
Another option is to run the application IIS instead of IIS Express...
My problem with this is that it ALWAYS adds the port, even when the port is not required. This can cause issues with multiple servers in some cases For example, in a production server environment behind a firewall on a pair of load-balanced web servers, it kept putting the firewall port in place, but that caused the URL to break because the port was tied to a specific web server in the server farm that wouldn't map correctly through the firewall. So I would be very careful with this method if you're using it across multiple servers. It caused a breaking issue with our application and had to be reverted back to using Url.Host. Plus, it made production web URL's look weird with the port number.

Move a Web Site project with a web service to AWS windows server

I've started ut a new instance of a windows server 2008 and am trying to move and launch my web service I've created in Visual Studio. How do I move the project from my local computer to the remote desktop? Grateful for all help!
I've tried the really simple approach and just copied the directory to the remote desktop in the same location as on my local computer. Did not work.. When I try to access the same adress that it has on my local computer (http://localhost:80/somesite all I get is this:
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
I'm probably going about this the wrong way, but don't know where to start..
Sounds like you need to setup IIS. See the following link http://www.codeproject.com/Articles/28693/Deploying-ASP-NET-Websites-on-IIS-7-0
I would make sure asp.net is enabled in the IIS server. Also try to explicitly hit your page such as:
http://localhost:80/somesite/myhome.aspx
I'm sure there is a quick answer to your particular issue, but if you're going to be doing this sort of thing often, it is best to take some time up front and read up, then click around and get a feel for IIS.
http://msdn.microsoft.com/en-us/library/ms178477.aspx
Visual Studio has abstracted much of the site/virtual directory setup and configuration, chances are you can't just copy the files over and have it work. There are lots of things to think about: websites versus virtual directories and their configurations, application pools and their identities, file permissions, default documents, etc. enjoy.

How do I test wildcard domain logic

Here is an interesting problem... I have configured wildcard domains on my production site and will be using it as a customer identifier. This allows me to display the right banner/css/logos for each customer simply be pulling out the wildcard prefix (eg. CompanyABC.website.com will be displayed the logos and branding related to CompanyABC).
But how do I test this on my local Visual Studio 2010 installation? In production the site loads COMPANY.website.com etc., but locally I can only use the flat http://localhost address.
Hosts file?
127.0.0.1 companyabc.website.local
Put the relevant code in a separate class and create a unit test for it.
Just get one more computer. I would prefer one more laptop. Make the IP dynamic and test it there. Results would give higher and accurate results, since your not testing different IPs on the same computer.

Categories