XML transformation not working - slowcheetah

I have installed the SlowCheetah extension and Nuget Package into my Console App Project. I have used the context menu to add a UAT build configuration and updated a test setting to check that the value is being transformed.
Unfortunately its not, when I try to Preview the Transform via the Context Menu its just showing me the non transformed App.Config.
What steps can I check to see why this extension is not working?
In the main App Config I have specified an appSetting.
<appSettings>
<add key="TomTestTransform" value="LOCAL" />
</appSettings>
In the App.UAT.config I overwrite it
<appSettings>
<add key="TomTestTransform" value="UAT" />
</appSettings>
When I preview the Transform, or build and check the configuration output, its always using the non transformed version. The setting equals LOCAL.

You need to use xdt: attributes to match and adapt the elements, like so:
<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations
see the web.comfig examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="TomTestTransform"
value="UAT"
xdt:Transform="Replace"
xdt:Locator="Match(key)" />
</appSettings>
</configuration>
With xdt:Locator="Match(key)" you are telling the processor to match the add element based on the key attribute, and apply xdt:Transform="Replace" logic on the whole (located) element.
There is a msdn entry available on possible XML transformations, which is also applicable for SlowCheetah transformations, as they are based on the same "technology".
Additionally, the extension overview has also some good documentation in it!

Related

Updating Azure App Service web.config to load .ttf font files

Wracking my brain but can't seem to find the solution. I have a .ttf font file, located on Azure storage blob, being used for a custom font on my Azure App Service site. I get a 404 "resource not found" error for this file.
After reading a ton of documentation on this, it seems I need to add a couple of lines of code, for a new "mimetype", to the web.config file. Older versions of Azure had this in "Extensions" or "Application Settings".
Other people show the ability to do so in Kudu under the "Debug" option. However, I can't seem to find either of those - "Configuration" shows environment variables and I don't see a "Debub" option in my Kudu portal.
Kudu Console without "Debug" option
How do I actually update the web.config file or at the very least be able to load a .ttf file???
Go to Kudu, then go to wwwroot folder and edit web.config file with the following, or just create one in case it's not there:
PS: previous image shows LogFiles folder, but it should be wwwwroot
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>

How to override web.config values in custom section in Azure Web App?

It is possible in Azure Web App to override web.config AppSettings section easily. E.g. if I have the following web.config:
<appSettings>
<add key="AllowedCORSOrigin" value="http://localhost:26674"/>
</appSettings>
I can override it in the app settings UI in the portal like that:
I have also a custom section in the web.config:
<AdWordsApi>
<add key="OAuth2RefreshToken" value="TOKEN" />
</AdWordsApi>
Is it possible to override it somehow as well? I have tried AdWordsApi.OAuth2RefreshToken and AdWordsApi:OAuth2RefreshToken, but that does not work that easily.
P.S. It's interesting to know if it's possible with other custom sections like e.g if I want another authentication mode on the server.
<system.web>
<authentication mode="None" />
</system.web>
Short answer is that it is not possible.
The mechanism you describes only works with App Settings and Connection Strings. High level, the way it works is:
Your Azure App Settings become environment variables
At runtime, a special module sets those dynamically in the .NET config system. Note that the physical web.config is never modified.
But it would be hard to make such mechanism work on arbitrary config sections, as those could not be dynamically affected without modifying the physical file.
If you are using Visual Studio use web.config transformations to change configuration settings depending on whether you are running locally or deploying to Azure:
How to Transform Web.config
In simple terms you create one more more build configurations (typically Debug & Release). In your Visual Studio solution right-click on your existing web.config file and click "Add Config Transform", this will create a Web.Debug.Config and Web.Release.Config file which you can then customise with specific settings depending on the environment. Link this with your Azure build configuration and you can then have any combination of settings for local and remote deployment.
This is old but leaving this reference to how to use Azure Resource Manager to potentially solve this.
You can transform the values by the listed in VSTS by doing the following steps in App.Release.config:-
Add xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" in configuration section
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>
Add xdt:Transform="Replace" in custom section like below
<AdWordsApi xdt:Transform="Replace">
<add key="OAuth2RefreshToken" value="TOKEN" />
</AdWordsApi>
Create variable token in the release pipeline e.g OAuth2RefreshToken
Then in file config use it as following
<AdWordsApi xdt:Transform="Replace">
<add key="OAuth2RefreshToken" value="#{OAuth2RefreshToken}#" />
</AdWordsApi>
If you are adding any in web.config --> Appsetting, you can overirde it in Azure App Service using variable prefix
Key Name: APPSETTING_AllowedCORSOrigin
Value: http://localhost:26674
https://learn.microsoft.com/en-us/azure/app-service/reference-app-settings?tabs=kudu%2Cdotnet#variable-prefixes

Turn Glimpse off completely

I am interested in being able to turn Glimpse off completely in the lightest weight way that I can manage. Between the glimpse documentat and the response to this question How to disable Glimpse, the difference between turning Glimpse.axd off and defaultRuntimePolicy="Off" the strongest "off" functionality I can see is setting the defaultRuntimePolicy to off in the web.config file.
However, this still loads a number of glimpse assemblies into my process as shown in the debugger - the answer to this question Why is Glimpse still running? sheds some light on why.
So what I've been doing is keeping around a GlimpseOff shelveset that comments out the glimpse configuration in my web.config file and also comments out the references in my .csproj file. And applying it when I really need glimpse turned off. This works, and I'm pretty sure it really does turn everything off fully, but it is pretty cumbersome.
The alternatives I've considered are (a) removing the glimpse nuget pacakges when I need to turn it off, which is even more cumbersome than my current solution or (b) creating a new build configuration in visual studio which doesn't include the glimpse modules and preforms a web.config transform to remove the configuration.
Neither of these seem optimal. Anyone have a better/cleaner/easier way to do this?
You could use an XML transform to remove the Glimpse entries in Release mode/production.
Adding these entries to web.release.config:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<configSections>
<section name="glimpse" xdt:Transform="Remove" />
</configSections>
<glimpse xdt:Transform="Remove"/>
<system.web>
<httpModules>
<add name="Glimpse" xdt:Transform="Remove"/>
</httpModules>
<httpHandlers>
<add path="glimpse.axd" xdt:Transform="Remove" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="Glimpse" xdt:Transform="Remove" />
</modules>
<handlers>
<add name="Glimpse" xdt:Transform="Remove" />
</handlers>
</system.webServer>
</configuration>
If you'd like, you can input this transform and your web.config into the Web Config Transform Tester to make sure it works for your app.

web.config causing problems with iis

Up until now I have only worked with this web.config within Visual Studio. However I am now trying to publish my website to IIS and there are errors associated with my web.config. It seems that it crashes on configuration data for a module.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<phpNet>
<classLibrary>
<add assembly="php_mcrypt.mng, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4ef6ed87c53048a3" section="mcrypt" />
<add assembly="php_curl.mng, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4ef6ed87c53048a3" section="curl" />
</classLibrary>
<scriptLibrary/>
</phpNet>
</configuration>
error:
This screenshot is when trying to double click on any "Feature" within the "Feature View" of IIS. However if i just hit the website via a browser the error is the same:
The configuration section 'phpNet' cannot be read because it is
missing a section declaration
phpNet is for Phalanger, and the extension should be installed but I do not know how to check that. Like I said though, this web.config and phalanger worked fine within visual studio so Im not sure whats wrong. Especially since the installer did install the samples in iis.
You are missing configuration section definition
<configSections>
<section name="phpNet" type="PHP.Core.ConfigurationSectionHandler, PhpNetCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=0a8e8c4c76728c71" />
Without this, .NET does not know the 'phpNet' configuration section.
Also this means, you don't have Phalanger installed using setup.exe. Here are some information about using Phalanger without proper installation (important is the part about configuration) http://www.php-compiler.net/blog/2011/installation-free-phalanger-web
I found this posting http://crdevelopment.net/2012/06/12/fixing-iis-error-the-configuration-section-system-web-extensions-cannot-be-read-because-it-is-missing-a-section-declaration/
which led me to check the application pools.
At which point I noticed there where multiples. I selected the phalangerAppPool and that got rid of my error, but brought about a new one.
Handler “PageHandlerFactory-Integrated” has a bad module
“ManagedPipelineHandler” in its module list
However that error was alot easier to resolve (fix)

CruiseControl.Net on Windows Server 2003 x64

I'm having an issue with CruiseControl.net where the web dashboard just won't work in IIS. I have tried switching ASP.Net between 64 and 32 bit modes and reinstalling cruise control, but nothing seems to work. Has anyone else had issues with CruiseControl.Net on 64 bit platforms?
Cheers,
Jamie
[Edit]
Thought I should clarify, I am getting a 404 error when I try access the website. I am using the correct address because it asks for authentication. The .aspx handler is working because I don't see the default.aspx page from the ccnet directory.
[Edit2]
I am using the default web.config that comes with ccnet, but here it is:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!-- Change this if (for example) you want to keep your dashboard config file under source control -->
<add key="DashboardConfigLocation" value="dashboard.config" />
</appSettings>
<system.web>
<httpHandlers>
<!-- Yes, we are overriding .aspx - don't delete this! We are using .aspx since we know it is already bound to ASP.NET. In future we might use a
different extension so that people can add their own ASP.NET pages if they want to, but we should make sure in that case to change how
URLs are created -->
<add verb="*" path="*.aspx" type="ThoughtWorks.CruiseControl.WebDashboard.MVC.ASPNET.HttpHandler,ThoughtWorks.CruiseControl.WebDashboard"/>
<add verb="*" path="*.xml" type="ThoughtWorks.CruiseControl.WebDashboard.MVC.ASPNET.HttpHandler,ThoughtWorks.CruiseControl.WebDashboard"/>
</httpHandlers>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="RemoteOnly" />
<authentication mode="Windows" />
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page within an application.
Set trace enabled="true" to enable application trace logging. If pageOutput="true", the
trace information will be displayed at the bottom of each page. Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your web application
root.
-->
<trace
enabled="false"
requestLimit="10"
pageOutput="true"
traceMode="SortByTime"
localOnly="true"
/>
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false" timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
It seems I needed to enable Web Service Extensions for ASP.Net. I'm still not getting an ASP.Net tab in the cruise control website properties, but it is working.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727> or C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727> for 64 bit
Type aspnet_regiis.exe – i
ASP.NET will register itself and show up in Web Service Extensions
Clarify a bit, does the web-dashboard function incorrectly? Does it not show up at all?
The webdashboard uses Nvelocity, not ASP.NET WebForms, so you have to register a custom HTTPHandler in the Web.config for it to work.
<add verb="*" path="*.aspx" type="ThoughtWorks.CruiseControl.WebDashboard.MVC.ASPNET.HttpHandler,ThoughtWorks.CruiseControl.WebDashboard"/>
Post up your web.config.
Since you just want to know whether it works... it does.
I'm running it on a 64-bit Windows Server 2008 without a problem.
So now we've established it works, perhaps you can describe your issue in more detail?
Could not comment, I wanted to add this to the aswer to Adam:
I had to use this command in CMD for Win2008 x64
"C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe" -s "W3SVC/1/ROOT/ccnet"

Resources