Does Azure Web App support string/token replacement in config files? - azure

I have a Web App that I deploy via YAML pipeline, but would like to see if it can be done via web app's Deployment Center.
I need to transform the IP address and userPrincipalName in the endpoint element, but it does not fall under AppSettings or connectionstring element. Is it possible to transform this kind of element via Web App, or am I stuck with YAML pipeline?
Here is snippet of my config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="API_AUTH_MODE" value="2" />
</appSettings>
<system.serviceModel>
<client>
<endpoint address="net.tcp://10.0.0.0:99/App1/Services/Service1"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Service1"
contract="Service1" name="NetTcpBinding_Service1">
<identity>
<userPrincipalName value="user#domain.local" />
</identity>
</endpoint>
<endpoint address="net.tcp://10.0.0.0:99/App1/Services/Service2"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Service2"
contract="Service2" name="NetTcpBinding_Service2">
<identity>
<userPrincipalName value="user#domain.local" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>

Is it possible to transform this kind of element via Web App, or am I stuck with YAML pipeline?
AFAIK, I am afraid you could not transform this kind of element via Web App at this mpment.
That because the IP address and userPrincipalName does not fall under AppSettings or connectionstring element.
So, we could not use the Application settings or connection strings to replace it. We have to resolve this issue with YAML pipeline.
BTW, we could use the Replace Tokens in the YAML pipeline to resolve it.
Hope this helps.

While it was answered correctly above - Web App cannot transform anything other than Appsettings or 'connectionstring`, I ended up doing the following:
Use XML Transform files to replace the strings needed, since there is dependency on build type
Use YAML file to access vault to do password replacements.
I could have used Web App to do the password replacements, but it is much easier to manage the pipeline/deployment/release via a single YAML file rather than split YAML and Web App.

Related

Basic of Azure WebJobs SDK

I would like to know about JobHostConfiguration on Azure WebJobs SDK.
Where I can find the config ? is it on app.config ?
How can JobHostConfiguration identified this is IsDevelopment or not ?
I cannot find it on app.config
What config that JobHostConfiguration read ?
Thank You
Where I can find the config ? is it on app.config ?
Yes, it is in app.config file. You also could add some new configs manually in this file.
How can JobHostConfiguration identified this is IsDevelopment or not ?
It depends on whether the JobHost is running in a Development environment. The default value is false. If you want it to be true, you could add the following code in app.config file to let the JobHost run in a
Development environment. And you could read this article to learn more about this configuration.
<appSettings>
<add key="AzureWebJobsEnv" value="Development"/>
</appSettings>
The result is like this:
What config that JobHostConfiguration read ?
It could read many information of config, such as the connection string of Azure Web Jobs. You could click New Project>Cloud>choose Azure WebJob to create a Web Jobs to try.
Read connection string in app.config file:
<connectionStrings>
<!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
<!-- For local execution, the value can be set either in this config file or through environment variables -->
<add name="AzureWebJobsDashboard" connectionString="your storage connection string" />
<add name="AzureWebJobsStorage" connectionString=" your storage connection string " />
</connectionStrings>

Access Nuget Packages hosted in private Nuget server in Azure Functions

How can I access nuget packages hosted in private nuget server in Azure Functions?. Is there any way I can specify my private nuget server info?
Thanks!
Krishh,
This is possible using a nuget.config file as you normally would:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyPrivateFeed" value="http://myhost/myfeed" />
... other feeds ...
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
Using Kudu, or another deployment method outlined here, copy that file to either the function folder or wwwroot (that would apply to all functions) and your config will be used.
There are several posts related to your question if we assume that your private nuget package can be deployed as a simple .Net library:
Execute pre-compiled .NET code as Azure Function
How do you include references to external assemblies in Azure Functions
How do I use external assemblies with Microsoft Azure Function Apps?
How to put the entry point of an Azure Function inside a .NET DLL?

Test/Production configuration for Azure WebJob

I have an Azure WebSite project with WebJob project accosiated with it. The WebJob project needs to connect to external SOAP service. AS a result I have to put in the app.config the following block:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_MyExternalClassName">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="<<external URL>>" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyExternalClassName" contract="xxxxx" name="WSHttpBinding_MyExternalClassName" />
</client>
</system.serviceModel>
The problem is that I need to change value of <<external URL>> in "endpoint" node for different deployment scenarios - testing and production.
WebJob SDK seems to take Connection strings and app settigns from parent application, but what abount this specific SOAP-related service setting ?
How can I manage testing/production scenario?
Put the soap URL appSettings section inside web.config. Then read it using ConfigurationManager or CloudConfigurationManager. Obviously you have to manually set the url in code when you create the wcf client.
<appSettings>
<add key="soapurl" value="http://..." />
</appSettings>

Configure Redis Session State on Azure

I've got the Redis Session State Provider working fine locally with my ASP.Net site and in Azure with my Azure Website. But I've got a question about configuration...
Is there any way to store the configuration for that in the Azure Website itself using the App Settings (or Configuration Strings) section in the Website Properties screen?
That would be very convenient because it would mean that I don't have to modify the web.config file when I publish. I already do this for connection strings and app settings, but I just don't see a way to do that for anything in the <system.web> node of the web.config file, like the <sessionState> node.
There isn't a way to change the behaviour of the provider-based session state from utilising the web.config file.
You could write your own provider and modify where it finds the connection details from so you can publish those details somewhere other than in the web.config, but this wouldn't be standard behaviour.
This question has the way to make this work.
<appSettings>
<add key="REDIS_CONNECTION_STRING" value="[your dev connection string]" />
</appSettings>
<system.web>
<sessionState mode="Custom" customProvider="RedisProvider">
<providers>
<add name="RedisProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="REDIS_CONNECTION_STRING" />
</providers>
</sessionState>
</system.web>
Then, in the portal, you can create an app setting with the name 'REDIS_CONNECTION_STRING' with the correct connection string. You cannot use connection strings section of web.config or azure portal. It must be app settings. Not sure why, but connection strings just uses whatever is in the web.config and is not replaced with what is in the portal.

Publishing Web.Config to Azure removes Azure storage connection string

I've got a web.config that contains my SQL connection string and my Azure Blob storage connection string.
A Web.Config transformation replaces my Local SQL connection string with the Azure one.
When I publish the site to Azure, the Blob storage connection string is deleted and replaced with a duplicate SQL connection string, but with the blob storage string's name.
The only way I've found to fix is to log in via FTP and manually change the erroneous Storage connection string with the correct one from my local machine.
How do I get VS to publish my web config to Azure and leave it alone!!!
Web.Config
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="StorageConnectionString" connectionString="DefaultEndpointsProtocol=https;AccountName=;AccountKey=" />
</connectionStrings>
Web.Release.Config
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=.database.windows.net,1433;Database=;User ID=#;Password=!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
I had a similar issue to yours. I'm not sure why but when you define the connection strings in the "Configure tab" in the azure portal and associate a "Linked Resource" on the linked resource tab it may override certain properties in the Web.config transform causing unexpected results. One of the options when you set up a new azure website is linking to (or creating a new) database to associate with your website - thereby automatically assigning the related connection string which may try to override your transform operation defined in the Web.Release.config.
Check and see if removing all connection strings and linked resources inside the "Azure Portal" fixes your problem. Just make sure that you have both your production database and storage connections strings defined properly in the Web.Release.config.
I struggled with this problem this morning and I came up with a solution for VS2015/17.
So I have an Azure VM, and to publish my web app on this machine, I used the Web deploy to an Azure VM proposed by VS.
I put my connection strings in an external file, so the useful part of my web.config looks like this :
</entityFramework>
<connectionStrings configSource="ConnectionStrings.config">
</connectionStrings>
</configuration>
in order to prevent VS of adding some connection strings during publication (ADO.Net code first MSSQL database connection string in my case), you can edit the following file in your project :
...\MyProject\Properties\PublishProfiles\YourPublishProfile - WebDeploy.pubxml
In this file look into the ItemGroup part and edit it to delete the connection strings you don't need:
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="MyProject.Models.MSSQL_DB" Order="1" Enabled="False">
<Destination Path="" />
<Object Type="DbCodeFirst">
<Source Path="DBContext" DbContext="MyProject.Models.MSSQL_DB, MyProject" Origin="Convention" />
</Object>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<here are some entries delete the ones you don't need/>
</ItemGroup>
Be careful, if you add a file in this repertory, there is chances that it breaks the publication process on VS. Don't add file, just edit.

Resources