There are 2 applications pointing to 2 different paths.
1. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
2. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
I want to keep my connection strings in 1 single file so that both the applications should be able to read the same.
Any idea?
You can try to store your connection strings in external .config file and include it in both web.config files. Here is how to export profile configuration into a dedicated configuration file.
This is web.config:
...
<system.web>
...
<profile configSource="profile.config" />
...
</system.web>
...
This is profile.config:
<profile>
<properties>
<add name="Name" type="String" />
<add name="Age" type="Int32" />
</properties>
</profile>
Make sure you use .config as the extension of your files so they cannot be served to the browser.
See this blog post for details
To use one .config file in multiple applications create a symbolic link to that file in each application folder and reference that link in web config. Use mklink command in elevated command prompt:
cd "c:\YourApplicationDirectoryWhereWebConfigIs"
mklink profile.config "c:\YourSharedConfigFilesDirectory\profile.config"
Related
i use asp .net core version 3.1.
i know that for disabling 8.3 name creation i can set NtfsDisable8dot3NameCreation vaule to 1 on below path.
"HKLM\SYSTEM\CurrentControleSet\Control\FileSystem"
but my problem is that i dont know how i can set this configuration in web.config file.
actualy i want to use web.config XMl code for solving this issue.
and i try below setting in webconfig but get error when run project.
<configuration>
<HKLM>
<SYSTEM>
<CurrentControleSet>
<Control>
<FileSystem>
<add key="NtfsDisable8dot3NameCreation" value="1"/>
</FileSystem>
</Control>
</CurrentControleSet>
</SYSTEM>
</HKLM>
</configuration>
Ok, I am using an external config file for my connection strings so each individual developer can have their own strings while developing. Normally, each dev has a different environment but we all publish to the same servers via web.release.config transforms.
However, when I publish from VS, it's not transforming from the web.release.config for the conn strings. I think it's because if you have the configSource attribute set to use an external config it ignores the transform.
Here's my web.config:
<connectionStrings configSource="userConn.config" />
And here's my userConn.config:
<?xml version="1.0"?>
<connectionStrings>
<add name="DefaultConnection"
providerName="System.Data.SqlClient"
connectionString="Data Source=XXXX;Initial Catalog=XXXX;user id=XXXX;password=XXXX;" />
<add name="ExtVariablesEntities"
providerName="System.Data.EntityClient" connectionString="metadata=res://*/Models.XXXX.csdl|res://*/Models.XXXX.ssdl|res://*/Models.ExtVariables.msl;provider=System.Data.SqlClient;provider connection string="data source=XXXX;initial catalog=XXXX;user id=XXXX;password=XXXX;MultipleActiveResultSets=True;App=EntityFramework;"" />
</connectionStrings>
After publishing, opening the actual web.config that made it to the server, it still has:
<connectionStrings configSource="userConn.config" />
Is there a workaround for this? I've had this setup before I just don't remember what the trick is.
Just an FYI that I was able to solve this by following this article: https://jshowers.com/simple-web-config-transforms-for-configuration-elements-that-use-configsource-and-external-files/
You end up with 3 custom config files - whatever you want to call them for dev, test and prod lets say. Then you will have 3 web config files dev, test and prod (these are your web config transform files) where you simply say:
<appSettings xdt:Transform="Replace" configSource="path.to.custom.config.file.depending.on.env">
In an open source ASP.NET application I'm working on, I need to keep certain data in the configuration file private, while still keeping it easy for people to build and debug it on their own machine. This is data such as API keys, Mail Settings, etc..
How would I keep this data separate and out of the git repository while still allowing people to just pull and build without having to set up a bunch of stuff?
In your config file you can define configSource:
<configuration>
<appSettings configSource="filepath1.config" />
<connectionStrings configSource="filepath2.config" />
<!--etc-->
</configuration>
Put the configurations that you need to keep private in a separate config file, then exclude them in your .gitignore.
Keep in mind that this will ignore the whole section and overwrite it with the context you have in the referenced file.
You can also do Configuration Transform, which allows you to only overwrite a small set of variables in sections. For example:
In your main Web.config:
<configuration>
<appSettings>
<add key="Key1" value="Something I dont't Care"/>
<add key="Key2" value="Something dummy"/>
</appSettings>
</configuration>
And in your Web.Release.config:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="Key2" value="Something I want to keep secret"
xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
In this case the "Key2" value that you want to keep private will be in a separate file, and you can exclude the Web.Release.config through .gitignore.
Also there's another approach that I never tried, which can also overwrite config using external file.
Hi I am looking for a solution where I have some common connection strings which I have
a common connections strings file but also need some specific add and remove connection strings in some sites...but do not see a way to do it...
<configuration>
<connectionStrings configSource="connections.config">
<remove name="AppConnectionString" />
<add name="AppConnectionString" connectionString="data source=(local);initial catalog=xyz;integrated security=True;MultipleActiveResultSets=True;" />
<connectionStrings/>
</configuration>
With file connections.config containing
<connectionStrings>
<add name="name" connectionString="conn_string" providerName="System.Data.SqlClient" />
<add name="name2" connectionString="conn_string2" providerName="System.Data.SqlClient" />
</connectionStrings>
Thanks,
Bala
If this does not work as you have expressed it above (which is a shame in my opinon), you have a number of other options:
Include the common connection strings in the connection string config, and then use the application settings config for the app-specific connection strings.
As an alternative, use a custom configuration file for the app-specific connection strings and load it in for each app.
When you build your apps inject the correct connection string keys into the config file using something like powershell. This script can run as a post build task in your build script.
Otherwise, when you package or stage your release, ask the release team to run the script as a manual step (or add it into your deployment script).
I am working on big ASP.NET project(we using ASP.NET 3.5) which comprised of 5 different WebSites and some shared assemblies. Recently I added custom section into web.config files for each site. When I deploy all these applications, each site is deployed separately under same app pool.
Is there any way to make this section editable in IIS on site level, just like you can edit ConnectionString section for each site?
Sections I added all look like this:
<sectionGroup name="RegistriesCustomSettings">
<section name="RegistriesSettings"
type="Registries.Business.Utilities.RegistriesConfigurations"/>
</sectionGroup >
<RegistriesCustomSettings>
<RegistriesSettings ContextCommandTimeout="30"
logLinq="true" DisplayUser="true" BaseReportPath="/DDD/"
ReportingServer="http://patriot-regdev:8000/ReportServer"
TopInstitution="1000001" />
</RegistriesCustomSettings>
We using are IIS 7.0, 2008 RC 2.
Yes there is a way to do this by extending the IIS configuration schema.
Create a file called RegistriesSchema.xml and copy and paste the following XML:
<configSchema>
<sectionSchema name="RegistriesCustomSettings">
<element name="RegistriesSettings">
<attribute name="ContextCommandTimeout"
type="int"
validationType="integerRange"
validationParameter="1,600"
allowInfinite="true"
defaultValue="30" />
<attribute name="logLinq"
type="bool"
defaultValue="True" />
<attribute name="DisplayUser"
type="bool"
defaultValue="True" />
<attribute name="BaseReportPath"
type="string"
validationType="nonEmptyString" />
<attribute name="ReportingServer"
type="string"
validationType="nonEmptyString" />
<attribute name="TopInstitution"
type="string"
validationType="nonEmptyString" />
</element>
</sectionSchema>
</configSchema>
Grab a copy of a tool called IisSchema.exe from here:
IISSCHEMA.EXE - A tool to register IIS7 configuration sections
Unzip and make sure both the exe and the xml schema file are in the same folder.
From an administrator command line (i.e. open cmd.exe using "Run As Administrator"):
IISSCHEMA.EXE /install RegistriesSchema.xml
This will do two things:
drops the schema file into %systemroot%\system32\inetsrv\config\schema
adds the following XML to applicationHost.config:
<section name="RegistriesCustomSettings"
overrideModeDefault="Allow"
allowDefinition="Everywhere" />
4 . Launch IIS Manager and open the feature settings for your website and open the Configuration Editor:
5 . Select the Section drop down list:
If all is good you should see "RegistriesCustomSettings", select this item.
6 . You can now edit these settings and they'll be added to your site's web.config file:
This is just a demonstration so the schema settings may not be quite right and will probably need some fine tuning.
What To Do With <sectionGroup name="RegistriesCustomSettings">?:
You will still need to add the configSection/sectionGroup xml to your web.config file for each site or you could add it to the root machine.config file for whatever version of ASP.NET you're using, i.e.:
For .NET Framework 2.0 (which also applies to .NET3.0 and 3.5):
%systemroot%\Microsoft.NET\Framework\v2.050727\CONFIG\machine.config
%systemroot%\Microsoft.NET\Framework64\v2.050727\CONFIG\machine.config
For .NET Framework 4.0:
%systemroot%\Microsoft.NET\Framework\v4.0.30319\CONFIG\machine.config
%systemroot%\Microsoft.NET\Framework64\v4.0.30319\CONFIG\machine.config
If you put your assembly's configSection/sectionGroup in your machine.config file(s) then you don't need to declare it in every site's web.config. If quite a few sites are going to be using this assembly then this may be good timesaver.
Update:
There seems to be a bug or limitation in the IIS7.5 Configuration Editor. It appears that if you have your own custom configSections <sectionGroup> or <section> declarations in your site's web.config file this breaks the IIS7.5 Configuration Editor. I'm trying to get to the bottom of this:
ASP.NET custom configuration section declaration breaks IIS Manager Configuration Editor
Update 2:
I think the MS docs on this are a bit bogus particularly where your custom config section needs to be consumable by ASP.NET and editable in the IIS Manager Configuration Editor. The trick seems to be to declare the schema as follows in the RegistriesSchema.xml file:
<configSchema>
<sectionSchema name="RegistriesCustomSettings/RegistriesSettings">
<attribute name="ContextCommandTimeout"
type="int"
validationType="integerRange"
validationParameter="1,600"
allowInfinite="true"
defaultValue="30" />
<attribute name="logLinq"
type="bool"
defaultValue="True" />
<attribute name="DisplayUser"
type="bool"
defaultValue="True" />
<attribute name="BaseReportPath"
type="string"
validationType="nonEmptyString" />
<attribute name="ReportingServer"
type="string"
validationType="nonEmptyString" />
<attribute name="TopInstitution"
type="string"
validationType="nonEmptyString" />
</sectionSchema>
</configSchema>
Also, and importantly, remove the section reference from applicationHost.config:
<section name="RegistriesCustomSettings"
overrideModeDefault="Allow"
allowDefinition="Everywhere" />
This is not required.
Additionally, you don't actually need to use the iisschema.exe tool, just grab a copy of NotePad2 (it's a 64bit editor, you need this to edit anything in inetsrv\config) and create the RegistriesSchema.xml file directly in inetsrv\config\schema.
You can find out more about extending the IIS7 schema here:
Extending IIS 7.0 Schema and Accessing the Custom Sections Using MWA
You can poke about the existing schema files to learn more about how to construct these settings. They can be found in:
%systemroot%\system32\inetsrv\config\schema
Caveat: The example above was tested on IIS7.5 x64 RTM on Windows 7 x64 Ultimate. You mention that you're running a release candidate so your mileage may vary because of that.