Environment Variables across different CNames hosted on Azure? - asp.net

The project I’m planning requires a site per client, after some research it seems that the best way to achieve this is with CNames. So if I have www.site.com, I can programmatically add a new site like client1.site.com.
The question I have is how would I have environment variables for each CName in an ASP.NET application that will be hosted on Azure?

So each client will have their own settings, site descriptions, colours, other custom options. If not environment variables, how can these be accessed?


If using CNames isn’t the best approach to this problem, what would be the best alternative?
EDIT
Only one copy of the application will be running that will be accessed through multiple CNAMEs

The problem you have here is that you apply environment variables to an individual application. If you want a set of environment variables per CNAME, then you need an application per CNAME.
A better solution would be to specify a wildcard domain for the Web App, and have all traffic directed to a single application. Then let the application check the incoming request for the CNAME and apply whatever parameters are required at that point.

Related

How do i scale my solution to multiple domains on single web application

Im a little lost here. Im starting on a project for a customer who wants a SaaS solution as a small portal.
The idea is that i make a web solution e.g. an online business card, where each customer should have their own domain like this:
www.carpenter.com
www.painter.com
www.masonry.com
Etc. each of these domains should point to my web application and each have their own administration web site and the online business card. This means that if I go to: www.carpenter.com I should see the companys online business card. And at the url: www.carpenter.com/admin the carpenter company should be able to log in and edit its information.
I hope this makes sense.
What Im looking at is how this is done in practice, I would like to have a central database and a central place to update my software (maybe one per country). What do i need to do to point a www.carpenter.com domain/url to its own specific area in my web app. And how do I need to structure my web application to do this?
Im using ASP.NET MVC for this, but this should be a general question regardless of language - or?
Im considering using a cloud service such as Azure, is this possible with this setup? Or do i need a virtual hosted server i own myself?
I guess the main question is "how do I host multiple domains on the same software" - and keep the display of the "business card" and admin separated from each customer?
Not sure if this specifically answers your question, and my experience thus far has not been with ASP, but I think the general idea is that you determine the execution environment for your web app early in the bootstrap process, and then set constants and configuration options at that point. Then, you can use those values throughout your application to customise the response based on which site you're working with (i.e. carpetner, masonry, etc.). And, since the only piece of differentiating information you have during the bootstrap process is the domain name and URL of the site being requested, I think the generally accepted method is to switch on the domain name. So, you can store different configs for the different sites based on their domain names, and then load those configs during the bootstrap process. For example, if you had a different site template for your carpentry site and your masonry site, you could store the path to your templates as one of the configuration options. HTH

How Can I Host Unlimited Unknown Domains on IIS?

In an upcoming version of a currently-in-development webapp, I need to serve multiple domains from a single site. The code on the site will recognize the individual domains and vary the content accordingly. I do not know all of the domains that we will be serving, as clients can add new domains to their site. The coding parts, I know how to do - when clients add a domain, there will be a corresponding entry into our database and that will act as a key to control which set of content is shown.
The thing is, I suck at system administration. The server already hosts a dozen different sites unrelated to this webapp, so it's not a situation where every domain that hits our server's IP can go through the code I describe above. If I knew the domains ahead of time, I could simply point them to our server's IP and then create bindings in IIS to handle each. But since I do not know the domains ahead of time, I'm rather at a loss. What can I do to enable my IIS7 server to support this situation?
After looking around a bit, I have found a few options for this.
1) Building It Into The Code
Probably the best option is to programmatically create bindings in IIS6 and in IIS7. This way everything is integrated into the webapp, meaning there's no muss or fuss outside of the app. It requires a bit more work in the app itself, but the benefits of keeping things clean and keeping all the functionality around this action inside the single codebase are almost definitely worth it.
2) PowerShell
Another option is to set up a script for powershell to have it handle this stuff based on the script detecting changes to the database. This would work well also, but has the drawback of creating two codebases to maintain.
3) Remove Domain Bindings
This answer led me to try removing the existing domain from the webapp's bindings in IIS. Making this change resulted in being able to reach my webapp by just visiting the IP address (so the binding was no longer an issue). And the one domain we have set for this webapp so far still reached the desired site as well. So it seems that the solution could be as simple as to have no host/domain listed in the bindings on IIS. As long as only one site does this, all traffic that does not match another binding loads that site. A big upside here is that it takes less time/effort than any of the coding solutions mentioned above. The downside is that you can only have one site on the server perform this way, and you can no longer have the server locked to only serving content with recognized domains.
Is it possible to add a extra ip address to the server?
This way you could let the IIS process all request on this IP address and run your logic for these request only. leaving the existing websites untouched.

Integrate multiple ASP.Net websites

I want to create a new website. The website has 3 applications, each one has its own membership/profile provider.
I want the user to be able to log in to the site with one single sign on.
Possible option AFAIK:
Define the same machinekeys/Connection Strings for all applications in their web.config files and I think I'm all set.
Does this work? And I'm curious to see if there's any other way.
Yeah, that is the path to go. Just make sure the config settings are identical and all three apps will work together just fine.
As a side: you say you want to build a new website with 3 applications. Are those "apps" separate sites or virtual directories of the top site? In other words, will they share the same URL?
The only issue I can think of is if the URL's are different then the session id's will also be different and therefore force the user to log in to each of them on access. This might be okay in your situation. With your method the credentials will be the same though.

Share application variable between 2 websites (IIS 7.5)

I have two urls that are supposed to lead to the same actual folder.
I can't do a redirect because the websites are built so they question the URL and perform accordingly.
So I built two application in the IIS (I tried using a virtual directory for one of them, but I kept crashing on the web.config can not be read). Everything works perfectly except the Application variables which are different between the two addresses. (Specificly I'm counting the number of current users logged on).
I tried to switch from InProc Session management to SQL, but that didn't solve the problem.
Maybe the solution is somewhere in the IIS so I'll have a proper redirection without using another application? Any ideas how to do that?
The SQL session manager would do the trick but you need to configure it specifically so that it thinks they are the same application. Is this user specific variable, or global application variable?
Since you basically have one app, but want two url's I would try to map them to the same app.
If it's two different host names you can use host headers in IIS to have them both go to the same web application.
If you want two different paths to go to the same application you should look into using the IIS Rewrite Module. Set up an application on one url, and create a rewrite rule to map the other url to the first one.
There's a lot of information on learn.iis.net about the URL Rewrite Module.

Can you create folders to organize web sites in IIS7?

I have several ASP.NET sites in IIS7 and would like to be able to group them into folders (or other mechanism, if available). Ideally, I would use a customer name or account number and put the sites under there.
Is there a way to customize the organization of sites in IIS7, or is there just the one 'flat' view?
I'm open to tricks and hacks.
IIS7 (or any other version) does not have the concept of folders for sites. I would instead come up with a naming scheme that, on sorting the list of sites, makes it easier to find what you need.
One option will be to add multiple applications under one site if they are related and on same domain of course. You can also have each applicatoin associates to its own application pool.
For example,
www.example.com
www.example.com/admin
www.example.com/auth

Resources