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?
Related
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.
Under MyProject > Properties > Web there is an option to "Apply server settings to all users" which stores the IIS config in MyProject.csproj.user.
However, there doesn't seem to be a way to set defaults. Meaning anyone who clones the project will have to customize these settings.
Is there a way to set defaults when using user-specific IIS settings?
I've attempted to use environment variables, but Visual Studio complains that it cannot create an IIS binding for http://$(API_HOST):$(API_PORT)/
What is the setting you need to set? This is an important detail.
Most of the configuration could be setted in the web.config file infact this file has a "system.webServer" section dedicated to IIS Configuration.
example:
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="Default.htm" />
<add value="Index.htm" />
<add value="Index.html" />
</files>
</defaultDocument>
<directoryBrowse enabled="true" />
<httpErrors>
<error statusCode="404" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="my_custom_404.htm" />
</httpErrors>
<security>
<authentication>
<anonymousAuthentication enabled="true" userName="IUSR" />
<basicAuthentication />
<clientCertificateMappingAuthentication />
<digestAuthentication />
<iisClientCertificateMappingAuthentication />
<windowsAuthentication />
</authentication>
<requestFiltering>
<fileExtensions allowUnlisted="true" applyToWebDAV="true" />
<verbs allowUnlisted="true" applyToWebDAV="true" />
<hiddenSegments applyToWebDAV="true">
<add segment="Web.config" />
</hiddenSegments>
</requestFiltering>
</security>
<staticContent lockAttributes="isDocFooterFileName">
<mimeMap fileExtension=".mp3" mimeType="otect/stream" />
</staticContent>
</system.webServer>
source:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/
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/).
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.
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