Multiple instances of site in one webrole with different web.config - azure

I would like to deploy my MVC3 app to Azure using multiple physical sites of the same app.
It's great that I can use the sites element in ServiceDefinition.csdef to do this.
But I want each of the sites to connect to a different database. The connection string is in the web.config. Is there an easy way to do this, besides logging into the vm and changing it by hand?

You could register a startup task to go and modify/move the web.config files when the VM starts up. It's a bit messy, but cleaner than doing it by hand!
http://msdn.microsoft.com/en-us/library/windowsazure/gg456327.aspx

[Answer to your comment] - With Windows Azure (actually with any PaaS solution) The first rule of thumb is that when the role starts all the configuration should be ready and the second rule of thumbs is that nothing should be done in VM through RDP access, because changes will not persist. Due to this required configuration either deployed in Azure Package or modified directly from start up task.
[Answer to your question]
In Windows Azure you can run multiple sites within one Web Role however they all should share the same main web.config because multiple sites are running within one Web Role. Here is how you can do it:
http://msdn.microsoft.com/en-us/library/windowsazure/gg433110.aspx
Now as your requirement is to have multiple databases, so in your web.config you can add multiple database connection string as below:
$
<ConnectionString>
<Add name="DB1" connectionString="Data Source=DS1.........."/>
<Add name="DB2" connectionString="Data Source=DS2.........."/>
</ConnectionString>
once you have above, in your ASP.NET code you can enumerate these connection strings and use with specific sites as described in the given example:
http://www.dotnetspark.com/kb/780-how-to-use-multiple-database-connection.aspx
Finally, you can add multiple sites with your web role during development and can also have specific DB connection specified in web.config so I dont think there is any need to use startup task at all or do something in VM, unless i am missing something here.

Related

Two Azure Cloud Services Single Domain

In IIS you can create an Application on a site so now I want to try and accomplish the same on Azure Cloud Service:
tenant.mysite.com - One Cloud Service
tenant.mysite.com/api - Another Cloud Service
The reason I want it done like this is cause this is a multi-tenant site and the api needs to be called with the tenants URL.
Is there any way out the box to do this with Azure? Am I looking at the whole solution wrong or do I have to look into doing a proxy of sorts?
I did host the application similar to what you have did.
There are a few points that you will need to take care of
1. Overlapping sections of web.config file should be locked using <location path='.'.... > tags
2. Proper references for the dlls to be given
This is easily achieved in both the Azure websites and Azure Cloud Services. The link that explains how you can get started is given below. Post questions if you have tried this and run into some issues.
http://blogs.msdn.com/b/tomholl/archive/2014/09/22/deploying-multiple-virtual-directories-to-a-single-azure-website.aspx

Azure Overlapped Recycling is not working

I have an azure web site i created to test azure and a web site. So far I like azure but i've run into a problem.
I am trying to run RavenDB embedded database in my website, as I'm not yet ready to get a full database.
RavenDB requires that the app pool is set to Disable Overlapped Recycle.
I followed the steps from this stack overflow article to achieve that:
Disable pool recycling on Azure Websites
When I download the applicationHost.config file i can see the line:
<recycling disallowOverlappingRotation="true" />
Which tells me the overlapped recycling should be disabled.
But i am still getting errors with my ravenDB database, which relates to the overlapped recycling.
Is there any other way to confirm that overlapped recycling is disabled or be able to modify my azure app pool. Without having to get a full support plan or something like that?
My application is Microsoft.Owin, so there is no global.asax or app_start folder. There is a startup class.

Migrating to Azure Web Role - porting the web.config file

I am migrating an existing Web Application to a Web Role. Does this mean that the web.config will be ignored?
I have connection strings, provider details, and tons of other config items in the web.config. Do I have to attempt to port all of this to the Azure ServiceConfiguration.Production.cscfg file?
In development, the Compute Emulator will not be used (since it takes so long), so we will still need the web.config files.
It depends on your use-case.
The cscfg allows you to reconfigure your WebRoles once deployed without creating a new package and redeploying/upgrading/staging+swapping. I especially think of scenarios where continuous integration is used and release procedures are no longer trivial.
If this scenario is not relevant you could just stick with the web.config and build and deploy new packages on configuration changes.
You could also selectively move items you assume that will regularly change in order to benefit from the configurability without having the effort of migrating everything.
I have used wrapper classes which abstract the configuration mechanisms (web.config app settings keys vs cscfg configurationsettings) in order to be able to use the different configuration mechanisms (e.g. check cscfg and fall back to web.config or the other way round or something along that lines).
Update: If you are using a "recent" azure SDK (1.7+) here is CloudConfigurationManager which might do most of the work for you.

Deploying and maintaining multiple copies of the same web application at different URLs on Azure

I'm currently investigating the possibility of my company using Azure.
Our current hosting situation that we run ourselves involves a separate site in IIS for each of our clients, each one having a virtual directory to the CMS we've built with ASP.Net web forms. We can update the contents of that virtual directory, which then provides the latest version of our CMS to all our clients at once.
I'm not looking to recreate that exact situation in Azure, but I am instead interested in figuring out how to create a single Web application in Visual Studio, publish that application to Azure in such a way that multiple sites (that I've specified) are created on Azure. Then I would like to be able to make changes to that application, and publish it again in a such a way that all the sites for it get updated all together, without requiring something be done manually per site/client.
The closest explanation I've found is this one:
http://www.wadewegner.com/2011/02/running-multiple-websites-in-a-windows-azure-web-role/
That gets me close, but what I don't understand is that when I publish this application to Azure, I still only see one application / URL available in the Azure management console. Shouldn't the extra "Site" node result in a different site being available when I publish it? Why doesn't it? Is there a completely separate way to accomplish this that I'm not using?
When you look at the management console you're seeing the web roles that you have deployed, not the sites that are part of that web role which is why you're only seeing one. As long as you've followed the instructions correctly, then yes, you do have two sites running. The catch is that you can only access the main site through that default URL. Presuming you have urls that look like customer1.mysite.com and customer2.mysite.com, you need to make sure you've set these as the host headers in the sub sites and then change your DNS so both of these domains point to URL you can see in the portal (e.g. mysite.cloudapp.net).
When considering a multi-tenant solution, ideally you should design your web-application as a single website that is capable of responding to multiple tenants (each of your customers), as opposed to creating a website/web-application for each one of them. This makes updates across the system manageable.
Your web-application can partition and identity different tenants based on several options such as part of the url (e.g myapp/tenant1 vs myapp/tenant2) or via a host header (e.g. tenant1.myapp.cloudapp.net vs tenant2.myapp.cloudapp.net)
HTH

WaIISHost.exe.config vs. app.config for worker role config

Posts seem to conflict in their description of how best to get web.config settings into an Azure worker role. Some posts say you need to create WaIISHost.exe.config, set output to always then copy relevant web.config info to that file. Other posts describe creation of app.config instead of WaIISHost.exe. Which is correct?
The answer to this depends a bit on the version of the SDK you are using. First and foremost, the WaIISHost.exe.config is only applicable to Web Roles (not worker roles). Worker Roles use and continue to use app.config for their configuration settings. I am going to assume here that you are trying to configure a Web Role's RoleEntryPoint in config settings.
Now, for Web Roles: If you are using the latest SDK (1.8 at time of writing), you will find that creating a WaIISHost.exe.config file (and copy local, etc.) no longer works. Something has changed in the latest SDK and it will no longer pull those values. For earlier versions of the SDK, this is still how you do it. For the latest version (and likely next versions) 1.8, you can create an app.config. When you do that, it will actually create a file in your bin directory like "WebRoleProjectName.dll.config". You DO NOT have to create this file manually yourself and "Copy Local". Simply create the app.config like you normally would and you will find that your RoleEntryPoint in the Web Role can be configured just fine like that.
In your previous SO post, I suggested that you would need to spend some time to understand both Windows Azure websites and Windows Azure Cloud services as you are mixing together.
Like above you are mixing web and worker role together. WaIISHost.exe is the Windows Azure Web Role Host process which is responsible for loading and running your Web Role DLL. This process has nothing to do with Worker role because it is not even existing in a Windows Azure Worker Role. This process will be only available to Web Roles. And because of that your question above "WaIISHost.exe.config vs. app.config for worker role config" is irrelevant.
App.config configuration is used with both Web Role and Worker Role, however web.config is only used with your web application. So if you want to configure Roles only you can use app.config (both with web and worker role) however for web site configuration you can use web.config.
IF you just write what your final objective is in simple word, you sure will get exact assistance and suggestion on how to do it.

Resources