Programmatically configure an EntLib CAB CacheManager - configuration

Currently I'm having to include a significant chunk of XML in the app.config to get the CAB CacheManager going and I'd rather hide the configuration away in my code.
Is there any way to programmatically configure an Enterprise Library Caching Application Block's CacheManager?

why don't you use configSource attribute in your web.config to move to another config file the CAB configuration?
For Example:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
....
</configSections>
<cachingConfiguration configSource="Config\Caching.config" />
And then, in Config\Caching.config:
<?xml version="1.0" encoding="utf-8" ?>
<cachingConfiguration defaultCacheManager="DefaultCacheManager">
<cacheManagers>
<add name="DefaultCacheManager"
expirationPollFrequencyInSeconds="60"
maximumElementsInCacheBeforeScavenging="1000"
numberToRemoveWhenScavenging="10"
backingStoreName="Null Storage"
type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
..
As far as I know, you can use a separate config file for each configSection in your web.config
s.

Related

PageSpeed Insigths and GoDaddy Windows Hosting

I'm having an issue with cache in my webpage.
My webpage is hosted by GoDaddy, with the Economic Windows Server with Plesk.
conexaomktdigital.com.br
It's a very simple site, I DONT USE PHP on it, only HTML, CSS and simple bootstrap JS.
When I run PageSpeed Insights, the results are telling me to optimize browser cache, including adding expire dates to my .css and images.
Mobile: 60/100
Desktop: 75/100
HOW I DO IT? I seek everywhere and don't see anything, everybody talks about .htaccess, but it's not apache, it's windows with plesk by GoDaddy... What should I do, can someone help me?
Create and use a correct 'Web.Config' file. put it in your root folder.
You can find some information about how to use a web.config file with te right tags here:
https://www.giftofspeed.com/leverage-browser-caching/
I use a very simple configuration, it appears to work nice for me:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<caching enabled="true" enableKernelCache="true">
<profiles>
<add extension=".html" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
</profiles>
</caching>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
</configuration>
this will keep the files listed there in cache until it have some change.
No Error 500 for me, I think it will not happen to you too.

The connectionstring property is not initialized

So, I realize that there are a lot of questions on here pertaining to this problem, but none seem to be the same as to what I'm dealing with. I had to delete my dataset out of visual studio and bring it back in. After doing so I got the error. I'm using mysql as a backend, so I'm using the dotconnect for mysql extension for visual studio. Everything was working fine until I did this step. Here is my app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="RMSteel.My.MySettings.RMSteelConnectionString" connectionString="User Id=rmsteel;Password=password;Host=192.168.0.46;Database=RMSteel;Persist Security Info=True"
providerName="Devart.Data.MySql" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Whenever I use my connection I use the name RMSteel.My.MySettings.RMSteelConnectionString, since this is auto-generated (I assume by dotconnect). I am fairly far in this project and would like to find a fix using this connection string, so I don't have to rewrite that much. Thanks for any help, and if you'd like me to post more code, I can.

Enterprise Library 6.0 - exceptional handling block-The configuration section for Exception Handling cannot be found in the configuration source

we are using enterprise library 6.0- exceptional handling block and configuration console for defining policy.
The following code has been generated in app.config file for the defined policy
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="DataAccessPolicy">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add name="Replace Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
exceptionMessage="An occured in the data
access layer.
Please Contact the
Admin with Error Id { }."
replaceExceptionType="Mindtree.Azure.PaymentGatewayExceptionHandler.DataAccessException, Mindtree.Azure.PaymentGatewayExceptionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
I have the following code in my catch block, i am defining manager using configuration source factory and setting the exception manager
IConfigurationSource config = ConfigurationSourceFactory.Create();
ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);
ExceptionPolicy.SetExceptionManager(factory.CreateManager())
bool rethrow = ExceptionPolicy.HandleException(ex,"DataAccessPolicy");
if(rethrow)
throw;
DataAccessPolicy is defined in the app.config file which uses the repalce handler
but the following error is thrown when debugging
The configuration section for Exception Handling cannot be found in the configuration source.
Any Help would be appereciated. Thanks in advance

Linqpad Error with EF DbContext: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

I happily run LinqPad 4.47.02 on a Win7 machine. I tried to add a EF5/dbContext connection. I choose my assembly, the class within the assembly and such assembly's config file. When I add the connection, i get this error:
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw
an exception.
My app.config contains this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="FipavContextContainer" connectionString="metadata=res://*/FipavContext.csdl|res://*/FipavContext.ssdl|res://*/FipavContext.msl;provider=MySql.Data.MySqlClient;provider connection string="server=127.0.0.1;User Id=root;database=fipavmanagerdb"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
I tried to comment the tag in configfile as suggested here but i get the same error.
As a side note, the connection worked and I have many saved linqpad queries. When I try to load and run one of them, linqpad crashes with no additional info.
What am I doing wrong?
Thank you,
F.
(weird) SOLUTION:
I tried moving the <configSections> tag just before <system.data> tag and the error flied away
As per msdn article for configSections element:
If this element is in a configuration file, it must be the first child element of the configuration element
I believe that one of the reasons is that this element defines handlers to handle custom sections in the config so if it is first you don't need to read parse config multiple time to handle a case where a custom section is defined before the handler for this section is defined.

Castle remoting sample - client throwing exception

I am using the sample from castle # http://old.castleproject.org/container/facilities/trunk/remoting/containersconnected.html for "Scenario: Using the container on both endpoints and use the container components"
The only update I have made to this is one line in the config files from type="Castle.Facilities.Remoting.RemotingFacility, Castle.MicroKernel"
to
type="Castle.Facilities.Remoting.RemotingFacility, Castle.Windsor" as suggested by Mauricio in question Castle remoting facility not working
I also updated the references in both the client and server to use latest castle dlls. The server starts up successfully but the client does not. I get the following exception on the client:
Could not set up component 'remote.console.component'. Type 'System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' does not implement service 'Example.Shared.IRemoteConsole, Example.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Any suggests on what I am doing wrong?
The following is the client config file
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/>
</configSections>
<castle>
<facilities>
<facility id="remote.facility"
type="Castle.Facilities.Remoting.RemotingFacility, Castle.Windsor"
baseUri="tcp://localhost:2133"
isClient="true"
remoteKernelUri="tcp://localhost:2133/kernel.rem"
remotingConfigurationFile="RemotingTcpConfigClient.config">
</facility>
</facilities>
<components>
<component
id="remote.console.component"
service="Example.Shared.IRemoteConsole, Example.Shared"
type="System.Object, mscorlib"
remoteclient="component"/>
</components>
</castle>
</configuration>
Replace:
<component
id="remote.console.component"
service="Example.Shared.IRemoteConsole, Example.Shared"
type="System.Object, mscorlib"
remoteclient="component"/>
with:
<component
id="remote.console.component"
type="Example.Shared.IRemoteConsole, Example.Shared"
remoteclient="component"/>