Advanced tasks using Web.Config transformation

As a matter of fact you can do this, but it is not as easy as you might think. You can create your own config transformation. I have just written a very detailed blog post at http://sedodream.com/2010/09/09/ExtendingXMLWebconfigConfigTransformation.aspx regarding this. But here are the hightlights: Create Class Library project Reference Web.Publishing.Tasks.dll (under %Program Files (x86)%MSBuild\Microsoft\VisualStudio\v10.0\Web folder) … Read more

Rewrite rule to HTTPS except when on localhost

Try this condition: <system.webServer> <rewrite> <rules> <rule name=”Redirect HTTP to HTTPS” stopProcessing=”true”> <match url=”^(.*)$”/> <conditions> <add input=”{HTTPS}” pattern=”^OFF$”/> <add input=”{HTTP_HOST}” matchType=”Pattern” pattern=”^localhost$” negate=”true” /> </conditions> <action type=”Redirect” url=”https://{HTTP_HOST}/{R:1}” redirectType=”SeeOther”/> </rule> </rules> </rewrite> </system.webServer> Using a negate condition against the localhost pattern should do the trick.

How do I use Web.Config transform on my connection strings?

This works for me but I too have found it to be a bit flakey at times. You will need to create another file called Web.Config.Release and fill it with the following: <configuration xmlns:xdt=”http://schemas.microsoft.com/XML-Document-Transform”> <connectionStrings> <add name=”local” connectionString=”Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword” xdt:Transform=”SetAttributes” xdt:Locator=”Match(name)”/> </connectionStrings> <system.web> <compilation xdt:Transform=”RemoveAttributes(debug)” /> </system.web> <appSettings> <add key=”default_db_connection” value=”local” xdt:Transform=”SetAttributes” xdt:Locator=”Match(key)” … Read more

Can you pull the connectionString for a log4net AdoNetAppender from elsewhere in a web.config file?

It is possible to use a DB connection string specified in web.config without creating a new class, though you would need to use log4net build that hasn’t been released yet. It can be downloaded from SVN repository http://svn.apache.org/viewvc/logging/log4net/trunk/ Your config will look as follows: <connectionStrings> <add name=”connStr” connectionString=”Data Source=localhost; …” /> </connectionStrings> <log4net> <appender name=”AdoNetAppender” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)