Hide value in app.config - visual-studio

I have app.config file with keys and values:
<appSettings>
<add key="Username" value="Admin" />
<add key="Password" value="123456" />
<add key="Port" value="22" />
</appSettings>
I know that best way to secure data in config file is encrypt/decrypt with RSAprovider as web.config then export key and import on another user's machine (I have done this before), but I do not need such "safe" solution.
I just want to hide password value to look like:
<appSettings>
<add key="Username" value="Admin" />
<add key="Password" value="******" />
<add key="Port" value="22" />
</appSettings>
or just like empty string.
I have googled a lot and I could not find anything to hide, but plenty stuff about encryption.
Is this possible to achieve this somehow?

No, app configs are plain text. If you had asterisks instead of the password, they would be interpreted as asterisks.

Related

Transform app.config entries only if a flag in app.debug.config is true

I would like to perform an xdt:Transform when in Debug configuration but only if the value of an entry in app.debug.config is a certain value, lets say true to keep it simple. For example:
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="Value.First" value="foo" />
<add key="Value.Second" value="foo" />
<add key="Value.Third" value="foo" />
</appSettings>
</configuration>
App.Debug.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<!--Convenient flag to indicate if transform should happen-->
<add key="Perform.Transform.If.True" value="true" xdt:Transform="Insert" />
<!--Should only happen if the above is true-->
<add key="Value.First" value="bar" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="Value.Second" value="bar" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="Value.Third" value="bar" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
I would like all of the Value.* entries in app.config to be transformed only if the key Perform.Transform.If.True is set to true. If it is false nothing should happen. The reason being that sometimes during testing we would like to quickly turn things on and off which are controlled by the config files.
I have seen the options for Locator for things like Match, Conditional, XPath, etc. but none seem to allow for a condition from another entry. Can that be done with slowcheetah/xdt transforms?
Well, found a round-about way using XPath:
<add
key="Value.First"
value="bar"
xdt:Transform="Replace"
xdt:Locator="XPath(//appSettings/add[#key='Perform.Transform.If.True' and translate(#value, 'ERTU', 'ertu')='true']/../add[#key='Value.First'])"
/>
If the flag is not true it will fail to resolve the path. The translate makes it case-insensitive.
Failing to resolve (is false) leads to compile warnings which is annoying but since this is a debug tool we can live with that.

Where is the package sources location

I use VS 2015 .Where in the visual studio project store the setting of Tools>options >Nuget Package Manager >Package Sources's setting. Currently Nuget.org is checked for Package Sources.I want to point this to a different location other than https://www.nuget.org/api/v2/, by editing the file location.
I checked the project file csproj, but did not find it
I need to change this manually in the server to point to the server repository. Working fine in local machine but not in the server.
This is a per-user setting, and is stored in %APPDATA%\NuGet\NuGet.Config. The file looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Abc" value="http://def/nuget/" />
<add key="Package source" value="http://packagesource" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
</configuration>
Simply add another entry into the <packageSources> element. (Mine is obviously updated for the protocol version 3 and so is referencing https://api.nuget.org/v3/index.json rather than https://www.nuget.org/api/v2/).

web.config transform: not the debug.cofig values when debugging locally

I am trying to change the values of some appsetting keys while running locally.
So, i have my original Web.config which has thoses keys
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="config" value="Release" />
</appSettings>
I am trying to change the value of "config" key in the web.debug.config,
<?xml version="1.0"?>
<!-- For more information on using Web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=301874 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="config" value="Debug" xdt:Transform="Replace" xdt:Locator="Match(key)" />
</appSettings>
<system.web>
</system.web>
</configuration>
When, i am running the project locally using VS:
I am printing the value of config and is always showing the value from web.config, however when i click preview transformation on web.debug.config, its showing this:
how can i make it work locally by picking information from web.debug.config?

How to Specify Last-Modified or ETag header to enable Cache Validation on IIS 8.5

I want to specify a cache validator for google font on IIS 8.5.
http://fonts.googleapis.com/css?family=Open+Sans:400,400italic,300,700,600
What I did on my web.config is below;
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00" />
</staticContent>
I also added caching by extension
<caching>
<profiles>
<add extension=".woff" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="23:59:00" />
<add extension=".ttf" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="23:59:00" />
<add extension=".gif" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="23:59:00" />
<add extension=".js" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="23:59:00" />
<add extension=".png" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="23:59:00" />
<add extension=".jpg" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="23:59:00" />
<add extension=".css" policy="CacheForTimePeriod" kernelCachePolicy="CacheUntilChange" duration="23:59:00" />
</profiles>
</caching>
But I am still not able to apply cache-validator for Google Font that I used. I am also tried to set an expire time to E.g. May 2030 for static content but Google PageSpeed didnt recognized that also. * I have managed to do it with .httaccess, and checked .htaccess topics on stackoverflow. *
You can apply a cache validor only for contents that your server sevrs not external content ;-).
Moreover it's a false positive because Google fonts have cache control directives:
https://redbot.org/?uri=http%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DOpen%2BSans%3A400%2C800

Why am I getting a "No attribute 'name' exists for the Match Locator" error when publishing?

I am so confused on this. I want to use the SQL Server on my desktop when I am developing and using the live SQL Server when I publish my project. I am playing with the transformation stuff in Visual Studio 2010.
I get the "No attribute 'name' exists for the Match Locator" when I try to publish my project.
My Web.config file contains:
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<sessionState mode="SQLServer" sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=eGov" timeout="20" allowCustomSqlDatabase="true" />
</system.web>
I am still testing it, so for now, my Web.Release.config file contains:
<connectionStrings>
<add name="EFDbContext"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<sessionState mode="SQLServer"
sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
timeout="20" allowCustomSqlDatabase="true"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</system.web>
Anything I am seeing online is only confusing me more. Any help to get me up and running?
xdt:Locator="Match(name) mean that system will match nodes to replace using name tag. If you don't have name attribute then it fails. You must have some unique attribute to use this type of transformation.
Doh! The problem was in the sessionState section. It should be:
<system.web>
<sessionState mode="SQLServer"
sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
timeout="20" allowCustomSqlDatabase="true"
xdt:Transform="SetAttributes" xdt:Locator="XPath(configuration/system.web/sessionState)" />
</system.web>
Using "name" in Match(name) is for a typical config setting like the following. The key in this case is "name".
<add name="errorAddress" email="me#google.com" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
If the key in your setting is something else, that is what you need to use:
<add token="UserToken" value="23jkl2klk2j3kja9d8f" xdt:Transform="SetAttributes" xdt:Locator="Match(token)"/>

Resources