Nesting appSettings with the file attribute - visual-studio-2010

I'm trying to pull off an inheritance chain of appSetting sections (VS2010 C#)
Given this,
Base.config
<appSettings>
<add key="basekey" value="basevalue"/>
</appSettings>
Derived.config
<appSettings file="Base.config">
<add key="derivedkey" value="derivedvalue" />
</appSettings>
App.config
<configuration>
<appSettings file="Derived.config">
<add key="mykey" value="myvalue" />
</appSettings>
</configuration>
This line:
ConfigurationManager.AppSettings["derivedkey"]
Throws exception:
Unrecognized attribute 'file'. Note that attribute names are case-sensitive. (...\Derived.config line 1)
It appears that App.config can successfully "file" over to Derived.config, but Derived.config is unable to "file" over to Base.config because "file" suddenly becomes an unknown attribute.
It's a little circular/confusing to me since the "file" attribute in App.config must be recognized successfully in order to reach Derived.config, where the same "file" attribute is suddenly unknown.

This is just not alllowed. You can not specify another external AppSetting file from within the first external AppSetting file.

Related

Role Provider error in web.config

My application is in Asp.Net MVC3, my application was running perfectly but all of a sudden i'm getting an error in my Web.Config in my role manager tag.
Below is my RoleManager tag of web.config
<roleManager defaultProvider="MASSIARoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<add name="MASSIARoleProvider" type="MASSIA.Helpers.MASSIARoleProvider, MASSIA" connectionStringName="MASSIAEntities" />
</providers>
</roleManager>
Below is the error i'm getting directly when i run my application:
[updated Error Image]
I have a file MASSIARoleProvider.cs in my solution in the directory Helper.
Below is Heirarchy of my RoleProvider file.
--> Massia --> Helpers --> MASSIARoleProvider.cs
My solution was executing perfectly but i'm getting this error all of a sudden.
<roleManager defaultProvider="MASSIARoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<add name="MASSIARoleProvider" type="MASSIA.Helpers.MASSIARoleProvider" connectionStringName="MASSIAEntities" />
</providers>
</roleManager>
Attemp 2:
Check for your MASSIARoleProvider file and see whether the Solution name and references used are perfectly correct.
Attempt 3:
The last and least recommended.
Create a new solution, if and only if your solution is in the beginning stage and try to reconfigure the RoleProvider. Once it solved the issue for me, I made a new solution, added the existing files to the news solution and executed the new solution and it executed perfectly. I did not made any change to the code, i just included the existing files from the old solution to the new one.

Web.config Remove ConnectionStrings node from Web.Release.Config

I have this in my Web.config so that my service will run locally:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=IPADD;Initial Catalog=DB;Persist Security Info=True;User ID=UN;Password=PW" />
</connectionStrings>
I need this here because the Web.Debug.Config doesn't work. So when I publish I want to remove this string because it is actually inherited from a parent Web.config
<connectionStrings>
<remove name="DefaultConnection"/>
</connectionStrings>
This doesn't seem to work... (it throws a The entry 'DefaultConnection' has already been added. error)
How can I remove it? XSLT?
P.s. I can't use clear/ because it removes the Machine.Config DB Connection string to the Membership provider also throwing a different error
Put below code:
<connectionStrings>
<add name="LocalizationDB"
xdt:Transform="Remove" xdt:Locator="Match(name)"/>
</connectionStrings>
But be careful when you do publish from visual studio. When you look on Output view. It should write you something like:
Transformed Web.config using Web.Release.config into obj\Debug\TransformWebConfig\transformed\Web.config.
Copying all files to temporary location below for package/publish:
But if you have active "Debug" you will have Web.Debug.config instead of Web.Release.config

Server specific Web.config replacement

I am currently using Visual Studio 2010. I want to set up a different connection string for my "Testing" Configuration. I have tried doing it by using config transformations, but it does not seem to work.
In my Web.config my connection string is the following:
<add name="MyDb" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DevelopmentDb;Integrated Security=SSPI; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
I found out that you can replace the connection string defined in Web.config by adding config transformation. I right clicked on Web.config and clicked on "Add config transformations". This created a Web.TEST.config file. I then added a connection string replacement, but it doesnt seem to work. It still uses the connection string defined in Web.config.
The file contents of Web.TEST.config is:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
-->
<connectionStrings>
<add name="MyDb"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TestDb;Integrated Security=SSPI; MultipleActiveResultSets=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
Any ideas to what I could be missing?
Transformations get applied when you deploy the project, not when you compile it.
If you are using IIS, you can deploy to the configured web application directory, which will cause the transform to apply.

Configuring Lightspeed for use in MVC3 Web project

I have a question regarding using LightSpeed in a MVC3 Web application. I am creating a REST Api project where I want to use LightSpeed, but the official configuration guidelines are quite vague. The official documentation says that the following lines need to be added to the file web.config:
<configSections>
<section name="lightSpeedContexts"
type="Mindscape.LightSpeed.Configuration.LightSpeedConfigurationSection, Mindscape.LightSpeed" />
</configSections>
<lightSpeedContexts>
<add name="Test" />
</lightSpeedContexts>
<lightSpeedContexts>
<add name="Test" dataProvider="SQLite3" />
</lightSpeedContexts>
I tried adding following lines to the web.config in the root:
<configSections>
<section name="lightSpeedContexts"
type="Mindscape.LightSpeed.Configuration.LightSpeedConfigurationSection, Mindscape.LightSpeed" />
</configSections>
<lightSpeedContexts>
<add name="Default" connectionStringName="Prod" dataProvider="MySQL5" />
</lightSpeedContexts>
<connectionStrings>
<add name="Prod" connectionString="server=localhost;User Id=production;password=xxx;Persist Security Info=True;database=CBS"/>
</connectionStrings>
This throws an exception when I start the Web application which tells me that configSections may not be specified more than once in the application. The root web.config file did not have any of these specified per default.
I am not sure where to put this configuration.
OK, I found out how to solve the problem.
I moved out the configSections that were in the two sub web.config files (in each Views folder) and put the contents in the main web.config file, then I added the lightSpeedContexts and connectionStrings in the main web.config file.

Windows Azure: asp.net <appsetting> for ChatHttpHandler not found

I have a problem in setting the chartHttpHandler in web.config for windows azure
Initially I added a chartHttpHandler on my web.config file
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
under system.webServer section
Then I got an error stating
Invalid temp directory in chart handler configuration [c:\TempImageFiles\].
Then I found that I should change in
From
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
To
<add key="ChartImageHandler" value="storage=file;timeout=20;" />
I am not able to find this section in my web.config file. So I tried to add it under section but it gave me error that it is an invalid child
Likewise, I tried adding it under section, it too gave the same error...
So, I added sepeartely, Then I am not able to see anything.. The webpage is just blank...
What should I have to do.. Can anyone tell me "how to solve it"
Looks like you need to add it in appSettings... http://blogs.msdn.com/deliant/archive/2008/12/02/managing-chart-generated-images-with-chart-image-handler.aspx
(No personal knowledge about this, but that's the first link I found via Bing.)

Resources