I'm in the process of deploying some windows azure projects and I've noticed that it's a bit of a pain to constantly switch my role configuration settings from using LocalStorage to actually use my Windows Azure Storage connection strings.
For local development, I want to use this:
UseDevelopmentStorage=true
But for deployed apps, I want to use something like:
DefaultEndpointsProtocol=https;AccountName=myAccountName;AccountKey=blah
I end up either changing my role's configuration connection strings just before I deploy, or if I forget to do that, I'll attempt to go into the Windows Azure portal and change them (but that usually happens after I watch my role instances start and stop over and over).
I feel like I'm missing something basic, but is there a straight-forward way to have the deployment process switch my role connection settings to use the production storage accounts instead of local storage?
You can use CloudConfigurationManager in Azure SDK 1.7 http://msdn.microsoft.com/en-us/LIBRARY/microsoft.windowsazure.cloudconfigurationmanager
This starts by looking in the ServiceConfiguration.cscfg e.g. ServiceConfiguration.Cloud.cscfg for config setting. If it isn't there it falls back to web.config and app.config
For example
CloudConfigurationManager.GetSetting("StorageConnectionString")
Will look in the appropriate cscfg file for StorageConnectionString setting, then it will search the web.config and then app.config.
If you want to use Visual Studio config transformations, see my answer to the question Panagiotis mentioned.
Switching from one connectionstring to another when moving from development to cloud
Cheers.
If you use CI server you can change the connection string there automatically. Details here.
I've answered a similar question here:
Visual Studio 2010 can apply Debug or Release transformations to Web.config, but what about the Azure settings?
Related
Every guide that I see say to do something with the web.config file in Azure. However, no matter how much I Google, there is nowhere to be found the steps that I need to take to find the web.config file. Your help will be highly appreciated :)
There are a few scenarios here. First: when you run on an App Service there is a web.config file. As David Makagon said, it's not accessible through the portal. By default, app services have Kudu available. One of the things this gives you is something like a file explorer. To access Kudu for an App Service with URL https://someapp.azurewebsites.net, go to https://someapp.SCM.azurewebsites.net.
A second thing you could do (which is part of Kudu) is use the App Service Editor. This is an online editor that looks very much like Visual Studio Code. Go to https://someapp.scm.azurewebsites.net/dev.
The third thing: if you have any settings in your web.config that you want to manage without updating the configuration file, have a look at the Application Settings. Any setting that's in there overrides the setting with the same name in the web.config.
I'm searching for ways to modify and edit app settings for Azure function during runtime.
from the links below, I was able to find how to add bindings locally and add connection settings through azure portal or Azure Cli
https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file
https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library#environment-variables
However, I'm searching for ways to generate new connection setting variables as well as new bindings at runtime.
The use case would be, where we need to onboard users without manually interacting with the Azure function app configuration.
I also tried modifying it thorough an example given in below link:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#environment-variables
I was able to modify the variable temporarily, but it appears that it loses the changes as soon as the run gets terminated (also, it didn't work when I published the app on Azure).
Is there way to accomplish this during runtime?
My set up is to have two azure functions:
1. dedicated to modifying app settings if change is detected in CosmosDB where new user information is added.
2. dedicated sending messages, but generating bindings based on app configurations added by azure function 1.
My initial thoughts were to store the whole app settings in cosmosDB and generate appsettings based on that document at every onetime, but I'm pretty sure there is better ways to do this.
also, it looks like my connection strings in local.settings.json don't get reflected when I actually publish them. what am I missing?
Thanks, in advance :)
I would like to update a database connection string in the web.config file for an application that is currently hosted in Azure as a web app.
Seems that you can RDP into an Azure cloud service role but not a web app. If you can't RDP into an Azure web app, is there another way to update the connection string without redeploying?
You can use the portal, there is a tool called "App Service Editor" in preview that lets you edit any of the files you've deployed. I do wonder why you want to do this though, it's not considered good practice to modify source files on the fly like this! Config and app settings are exposed via the portal as well and can be modified without dropping to the app service editor tool. (under Settings/Application Settings in portal). Updating these does not update the web.config but will override web.config settings.
As Russell Young said, on Azure portal, we could use App Service Editor that provides an in-browser editing experience for our App code. And we could specify connection string in App settings section to override existing settings.
Besides, we could also to access and update Web.config file (under D:\home\site\wwwroot folder) via Kudu Debug console.
The best practise would be to use a FTP client such as File Zilla, where you can grab it, edit, save and push it back to the host without the hassle of logging into a portal and editing it directly on the server or portal.
Please note that editing a file without backing it up first, and editing a file directly on the server can cause many many problems.
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.
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.