I am trying to add a set of URL Rewriting rules but only to the published version of the web site I'm developing.
I find all sorts of examples if i want to change say the connection string value, but I cannot find an example of how to add something that does ot already exists in the main web.config.
What I need is to add the rewrite node under the system.WebServer.
All you need is to use xdt:Transform="Insert" attribute within a tag that you want added during transformation. Read more about it here: http://msdn.microsoft.com/en-us/library/dd465326.aspx
You can take the below sample as a starting point (which is my Web.Release.config file):
<?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">
<!-- Enable static content caching in release mode -->
<system.webServer xdt:Transform="Insert">
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="5.00:00:00" cacheControlCustom="public" />
</staticContent>
</system.webServer>
</configuration>
Related
I've inherited an app that uses NHibernate and FluentNibernate to connect to an Oracle database. Unfortunately, I have no experience with NHibernate. The current connection string is like so:
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=0000)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=servicename)));User Id={username};Password={password};
but now needs to switch over to LDAP (see the last code snippet).
My question, is it possible to make a change only to the web.config with an LDAP connection or will I need to add the Oracle.ManagedDataAccess and make some code changes?
It is my understanding that OracleClientConfiguration has been deprecated based on this page hence the part of the question about a new nuget package. Another note, there isn't a hibernate.cfg.xml file within the project (which I think is ok?) but wondering if this project isn't using the best practices for NHibernate. Any other hints or tips would be appreciated.
C# code:
private ISessionFactory GetSessionFactory()
{
var connectionString = LoginHelper.GetConnectionString(ConnectionStringSetting, LoginInfoSetting);
var iSessionFactory
= Fluently
.Configure()
.Database(OracleClientConfiguration.Oracle10.ConnectionString(connectionString))
.Mappings(e => e.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
.BuildSessionFactory();
return iSessionFactory;
}
Web.config (there no other references to NHibernate in the Web.config. There are some references to dependentAssembly in other dll.config files):
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<configSections>
<configuration>
What I (think I) need in the Web.config is something like so:
<oracle.dataaccess.client> <!-- or <oracle.manageddataaccess.client>? -->
<version number="*">
<LDAPsettings>
<LDAPsetting name="DIRECTORY_SERVERS" value="" />
<LDAPsetting name="DIRECTORY_SERVER_TYPE" value="" />
<LDAPsetting name="DEFAULT_ADMIN_CONTEXT" value="" />
</LDAPsettings>
<settings>
<setting name="NAMES.DIRECTORY_PATH" value="" />
<setting name="LDAP_ADMIN" value="" />
</settings>
</version>
</oracle.dataaccess.client>
EDIT 1:
Contents of ldap.ora file:
DIRECTORY_SERVERS=(ldap:XXX)
DEFAULT_ADMIN_CONTEXT="dc=Oracle,dc=com"
DIRECTORY_SERVER_TYPE=ad
Here is what I did in order to get this to work...
In the Oracle folder structure, navigate to the Network folder.
Add the following files (should be able to copy and paste another folder down called Sample):
sqlnet.ora
ldap.ora
tnsnames.ora
sqlnet.ora (the key here was adding LDAP to the beginning of the list):
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, EZCONNECT)
ldap.ora:
DIRECTORY_SERVERS=(ldap:XXX:XXX)
DEFAULT_ADMIN_CONTEXT="dc=oracle,dc=com"
DIRECTORY_SERVER_TYPE=XX
tnsnames.ora:
No change was required; left as default
Connection string:
<add name="connection" connectionString="Data Source=YourDataSource"/>
<!-- might need to add a username/password -->
According documentation it should be this:
<LDAPsettings>
<LDAPsetting name="DIRECTORY_TYPE" value="AD" />
<LDAPsetting name="DEFAULT_ADMIN_CONTEXT" value="dc=Oracle,dc=com"/>
</LDAPsettings>
Or use
<settings>
<setting name="TNS_ADMIN" value="C:\oracle\work"/>
</settings>
and specify LDAP settings in C:\oracle\work\ldap.ora file (in conjunction with C:\oracle\work\sqlnet.ora file).
I don't think it is still valid but have a look at ODP.NET Managed library does resolve alias, but 32-bit library does
You can modify the config file with a simple text editor or use the config tool OraProvCfg.exe. Would be like this:
OraProvCfg.exe /action:config /product:odpm /frameworkversion:v4.0.30319 /providerpath:C:\oracle\product\12.1\Client_x64\odp.net\managed\common\Oracle.ManagedDataAccess.dll /set:settings\TNS_ADMIN:C:\oracle\network\admin
OraProvCfg.exe /action:config /product:odpm /frameworkversion:v4.0.30319 /providerpath:C:\oracle\product\12.1\Client_x64\odp.net\managed\common\Oracle.ManagedDataAccess.dll /set:LDAPsettings\DIRECTORY_TYPE:ad
Note, you have a OraProvCfg.exe for 32-bit (x86) and for 64-bit. Run the one which matches to your application, (or simply run both).
Currently, in my web.config file I have
<configuration>
<general path="c:\abc\" />
</configuration>
I want to change c: to d: when I publish the release version.
How do I do this in a transform?
The <general> section is much much bigger so I don't want to rewrite then entire thing, just that one attribute. Can anyone help?
Update: I created the following web.release.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
<General dataFilePath="D:\Data" xdt:Transform="SetAttributes" xdt:Locator="Match(dataFilePath)" />
<AuditManagement auditPath="D:\Audit" xdt:Transform="SetAttributes" xdt:Locator="Match(auditPath)" />
</configuration>
This had no effect on the final web.config. It still shows "C:\" where I would want "D:\"
You can try adding these attributes to the Web.Release.config:
xdt:Transform="SetAttributes" xdt:Locator="Match(path)"
so your final result should be:
<configuration>
<general path="d:\abc\" xdt:Transform="SetAttributes" xdt:Locator="Match(path)"/>
</configuration>
I would recommend you to use transformation
First you have to create the different enviroments for debug or release, and if you want you can add more.
This tutorial is well explained and tested by me:
http://deanhume.com/home/blogpost/working-with-multiple-web-config-files/4100
And here is the official documentation:
https://msdn.microsoft.com/en-us/library/dd465326%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
as it is explained in the previous your configuration for the web.config will be:
<configuration>
<general path="d:\abc\" xdt:Transform="SetAttributes" xdt:Locator="Match(path)"/>
</configuration>
and then you will have to define the correct path in the Debug and Realease configs, once it's finished you will run the app with one of the configurations you set.
I have consolidated the connection string information for a number of C# .NET solutions that are in my possession. Previously, each project was storing its connection string in its own format, requiring me to modify several files for each installation of the software.
Only one remaining solution is giving me trouble. This particular solution uses Castle Windsor 2.0, ActiveRecord 2.0 and NHibernate 2.1. The code reads its configuration from an XML file. I wish to remove the connection string from the config file and set it programmatically in the code.
Here is the relevant section of code that initiates Windsor:
windsorContainer = new WindsorContainer(new XmlInterpreter(xmlFileName));
windsorContainer.Resolve<IWindsorConfigurator>().Configure(windsorContainer);
logger = windsorContainer.Resolve<ILogger>();
Here are the contents of the XML file:
<?xml version="1.0"?>
<configuration>
<properties>
<connectionString>Server=*****;Database=*****;User Id=*****;Password=*****</connectionString>
</properties>
<facilities>
<facility id="logging" type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging" loggingApi="log4net" configFile="Configs/log4net.config" />
<facility id="atm" type="Castle.Facilities.AutomaticTransactionManagement.TransactionFacility, Castle.Facilities.AutomaticTransactionManagement" />
<facility id="arfacility" type="Castle.Facilities.ActiveRecordIntegration.ActiveRecordFacility, Castle.Facilities.ActiveRecordIntegration" isDebug="false" isWeb="false">
<!-- Configure the namespaces for the models using Active Record Integration -->
<assemblies>
<item>ChronoSteril.Application</item>
</assemblies>
<config>
<add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="connection.connection_string" value="#{connectionString}" />
<add key="hibernate.cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache" />
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
<add key="hibernate.expiration" value="60" />
</config>
</facility>
</facilities>
<components>
<component id="windsorConfigurator" service="ChronoSteril.Application.IWindsorConfigurator, ChronoSteril.Application" type="ChronoSteril.WinApp.ClarionIntegrationWindsorConfigurator, ChronoSteril.WinApp" />
</components>
I am not familiar with Windsor. During my Google tour, I did see some code that adds facilities programmatically, but those examples were not valid for my version of Windsor (I assume).
Question: Can anyone guide me in removing the connection string information from the XML file and allow me to set it in the code?
Thank you!
I managed to accomplish my intention. It is not ideal, but will work until the code base is rewritten. (I cannot wait to drop the existing code like a bad dream.)
Patrick's comment, under my initial question, let me to refine my search criteria, which yielded the thread located here.
My XML file remains the same, except that I use bogus values for the connection string information. I will never need to modify these, and they do not reveal any valid connection information. This was my intention. I still have not discovered how to successfully remove the ActiveRecord configuration from the XML file and configure using code.
I now call a method that contains the following code:
ISessionFactoryHolder sessionFactoryHolder = ActiveRecordMediator.GetSessionFactoryHolder();
NHibernate.Cfg.Configuration configuration = sessionFactoryHolder.GetConfiguration(typeof(ActiveRecordBase));
connectionString = ReadConnectionString();
configuration.SetProperty("connection.connection_string", connectionString);
This works for me. I hope that it can also help someone else who is in the same position as I was.
Currently i'm facing an issue with a framework I'm developing.
I have a custom configuration section that handles data caching.
The configuration for this is stored in the web.config of the application as shown below.
<configSections>
<section name="CachingProviders"
type="Data.Caching.Providers.Configuration.CachingProviderConfigurationSection, Data.Caching" />
</configSections>
<!-- Start the DCF configuration here. -->
<CachingProviders>
<!-- Providers definition:
A provider is the object that make sure that the item can be stored in the cache or not.
-->
<Providers>
<Provider Name="SlidingCachingProvider" Time="5" IsDefault="False"
Type="Data.Caching.Providers.SlidingProvider, Data.Caching.Providers" />
<Provider Name="AbsoluteCachingProvider" Time="5" IsDefault="False"
Type="Data.Caching.Providers.AbsoluteProvider, Data.Caching.Providers" />
</Providers>
</CachingProviders>
Now, the code is working fine, I'm reading the configuration from the web.config
But now I want to know if there's an easy way to transform my code so that the configuration can be done in a seperate file in the bin directory, for example: data-caching.config
I know there is a solution that in the custom config section you define which file to load, but I want to keep my web.config as clean as possible, which means that I don't want to add a single thing if possible.
You can add a configSource attribute to your Providers node as:
<Providers configSource="providers.config"/>
See here and here. This should work for custom sections as well.
I'm updating a site into a more dynamic version of the site. And in the new site I use hash tags rather than a new page for every change in content.
I'm using web.config files in directories to redirect but it's adding a backslash. Is there anyway to avoid this? I'm already handling it in the redirect, but I feel it's kinda kludgy.
Here is an example web.config
<?xml version="1.0"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="/legal/#!terms-of-use" />
</system.webServer>
</configuration>
Edit: It's worth mentioning, that instead of going to "/legal/#!terms-of-use" it goes to "/legal/#!terms-of-use/" Note the backslash at the end.
Turn on exactDestination in your redirect element, as below:
<httpRedirect enabled="true" destination="/legal/#!terms-of-use" exactDestination="true" />