Is it possible to a custom configuration section inside of an Azure Cloud Service Configuration, the same way you would in a regular ASP.NET website?
I.e in a regular ASP.NET site your Web.Config would have something like this:
<configuration>
<configSections>
<section name="myCustomConfig" type="MyNamespace.MyType" />
</configSections>
<myCustomConfig someProperty="someValue" />
</configuration>
How is this done in Cloud Services and shared across multiple different roles?
At this time I do not believe this is possible. There is a post for it on user voice you can vote up: http://www.mygreatwindowsazureidea.com/forums/169386-cloud-services-web-and-worker-role-/suggestions/459944-enable-custom-configuration-sections-in-csdef-cscf.
As a way around this you could put configuration into a file that is stored in BLOB storage. On start up, or when it is needed, all instances could then go pull the file to get the configuration. To deal with changes to the configuration you could either have the instances pulling the configuration from time to time as a refresher, or you could tap into the environment changed event in RoleEntryPoint that is used to detect changes to the Service Configuration. Add a setting to the service configuration that is a version number of your shared config file or something, just anything that could be modified to trigger the RoleEnvironment.Changing event.
Related
I have an API deployed as an Azure Website (not a worker role). The code for the site has Trace statements dotted through it that I would like to capture in an Azure Table via the Azure Diagnostics.
I'm using Trace.TraceError, Trace.TraceInformation, etc.
I've followed the instructions here, which essentially say that all that is required is to flick the switch in the management portal and set a location for Application Diagnostics: https://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/
I have ensured that the Microsoft.WindowsAzure.Diagnostics reference is added to the project, and I have also tried adding the following to the Web.config (even though the instructions don't say this is necessary):
<system.diagnostics>
<trace autoflush="true" indentsize="4" >
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics" />
</listeners>
</trace>
</system.diagnostics>
Despite this, the only output I get to the Azure Blob and/or Table (that I specified in the portal) is the following:
24/06/2015 14:02:49 AlasdairOTCDev Verbose SnapshotHelper::RestoreSnapshotInternal SUCCESS - process 11284 -1
24/06/2015 14:02:48 AlasdairOTCDev Verbose SnapshotHelper::RestoreSnapshotInternal SUCCESS - File.Copy 11284 -1
Trace levels are set to Verbose in the portal.
What am I doing wrong, and how can I debug this?
Many thanks for any assistance that can be provided as I'm rapidly running out of hair to pull out...
It turns out the root of the problem was with our build.
There was an issue where our build script was not compiling the TRACE symbol. Builds compiled locally did include this (which is why it all appeared to work locally) but when we built and deployed to Azure it was being missed out.
Without the TRACE symbol, none of the logging statements were activated.
You don't need the reference to Microsoft.WindowsAzure.Diagnostics in your project. That is for Cloud Services and the article you referenced does not mention it since it is for Azure Web Apps (formerly Websites).
Assuming you are using an Azure Web App (not a cloud service web role), then you have to use the current Azure Management portal at https://manage.windowsazure.com if you want to configure your web app to store application diagnostics to an Azure Storage Table or Azure Storage Blob Container. In the configure page for the web app, your configuration should look like this for a table storage.
(Currently, the preview portal at https://portal.azure.com only lets you configure application diagnostics logging using the web app's file system)
For anyone who still encounters this problem, besides for the excellent answers given on this page (enable tracing on azure, and making sure TRACE is set to true in your build), make sure you actually flush the traces!
In your code you need something like this:
System.Diagnostics.Trace.TraceError("Can you see me?");
System.Diagnostics.Trace.Flush();
Or
System.Diagnostics.Trace.AutoFlush = true;
System.Diagnostics.Trace.TraceError("Can you see me?");
I am trying to understand how I can configure my .NET website to display each domain or groups of domains as Applications in the New Relic RPM console.
There is an article explaining here how to do it for PHP
https://newrelic.com/docs/php/per-directory-settings
Applications can be named individually in the application's web config file. This is done by adding the following to the <appSettings> element:
<appSettings>
<add key="NewRelic.AppName" value="my_web_app" />
<add key="NewRelic.AgentEnabled" value="true" />
</appSettings>
Multiple instances of an application can report to the same name in the New Relic UI by giving each application instance the same name as shown above.
Of course, you can separate applications by giving them different names.
You can use this naming feature to group application instances by name as you need. Your application instances can be running on the same server, on different servers, or on a mix of these.
See this page for some additional information on application naming.
Note that you can also enable/disable monitoring of an application or application instance using the NewRelic.AgentEnabled key in the app settings section.
At this time, the .NET agent doesn't support differentiating which
application to report to based on the hostname of each request.
https://discuss.newrelic.com/t/report-websites-or-applications-running-in-the-same-iis-app-pool-as-different-new-relic-applications/36828
UPDATE December 2017: Please go to the URL above and vote for the feature if you think this feature would be useful.
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.
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.
We have two asp.net web applications (Two asp web projects in one solution)
Both are hosted on IIS. Both apps expose WCF services.
Those services read and write files to the file system. In each service, we determine where to read and write files from using :
HttpContext.Current.Server.MapPath(".")
So in this way, each service writes and read from the folder of it's web app.
We want the services to read and write from the same place (We want this to happen in development and production ).
Is there a way to achieve this ?
Just an idea, define the same path in web.config of both web applications. Use the defined path instead of getting Server.MapPath(".").
web.config:
<configuration>
<appSettings>
<add key="Path" value="c:\\somefolder\\"/>
</appSettings>
</configuration>
C#:
ConfigurationManager.AppSettings["Path"]