Using an External Config File With log4net with ASP.NET 2.0 and IIS7

I started a new project recently and set about adding log4net to it.  I’d upgraded to a new Window 7 workstation over the past month whereas I’d previously been using XP, so the step up to IIS7 was exciting and and a bit anxious all at the same time.  My first hurdle so far has been using log4net.

I tend to be the type of person that likes to separate out the log4net configuration into it’s own file, usually log4net.config.  Setting up this new project; however, I started running into a problem I’d never seen before.  When trying to use the XmlConfiguratior to read my log4net.config, I would see this exception:

[SecurityException: Request for the permission of type ‘System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.]

Searching for others with this problem has not yielded much success.  I’ve seen articles stating that it’s an issue with medium trust security (on m local workstation trust was set to full) to problems with some sort of breaking code within log4net itself.  Most of these articles I suspect were not using IIS7, but it was hard to tell.

I ended up digging into the log4net source code to find out what was happening.  The problem would occur on a line of code that tried to access the FullName property of a System.IO.FileInfo object.  That property threw the exception worked fine it I tried to access it from my web project, but once it got down into the log4net guts, it would not.

After a lot of frustration, I finally started looking elsewhere.  I ran across a comment on Stack Overflow that stated they used .xml instead of .config files.  I had dismissed it due since others claimed .config files where fine, but recalling what I’d seen there I decided to try it.  *Poof* it worked!

I didn’t really want to leave the configuration in a file with the .xml extension since that could easily be downloaded from a server.  The discovery told me that it was likely due to something IIS was doing with ASP.NET to hide files, but the odd thing was that it could read from the web.config, so I was a little perplexed.  I started digging into how IIS7 handles these types of protected files. 

IIS7 ManagerIt turns out that there’s a section in the hosting configuration that lists protected files under the name “requestFiltering”.  Hmm…that was an interesting sounding name.  Unfortunately all the entries were only by file extension, not by file name directly so there had to be something else.

Request FilteringI ended up in the IIS7 Manager application and found the Request Filtering area.  I began to poke around in there and discovered another tab called Hidden Segments which had an entry for the web.config!  I clicked the Add Hidden Segment link under Actions and added a new entry for log4net.config and viola, my application worked!

I know that most of the IIS7 configuration settings are stored in various config files, including the web.config, so I started looking in there and found this new element in the <system.webServer> section.

   1: <security>

   2:     <requestFiltering>

   3:         <hiddenSegments>

   4:             <add segment="log4net.config" />

   5:         </hiddenSegments>

   6:     </requestFiltering>

   7: </security>

I believe that including this section will allow the files to work.  I even changed my trust level in my dev environment to Medium and it still ran just fine.

There may be other things that can cause this sort of problem, but this fixed my example.  Hopefully this helps someone else out there as it was a bear to track down!

How To Create Custom Libraries in Windows 7

Default Windows 7 Libraries I recently discovered a cool little feature in Windows 7.  I’d known about the libraries that come default, which include Documents, Music, Pictures and Videos.  I thought that it was a nice idea that these libraries looked in multiple locations.  While I hadn’t had much need for it yet, I can envision my home network utilizing it once I start upgrading my home machines.

At work, I’m testing the 64-bit version of Windows 7 RTM as a developer workstation in our environment.  One thing that I constantly kept doing while making sure my environment is set up correctly, is looking for an application in the C:\Program Files folder.  Unfortunately, there are quite a few applications that are still 32-bit, so they get installed in C:\Program Files (x86) so I find that although I have a 50% chance to look in the right folder, I get it wrong about 90% of the time.  Wouldn’t it be great if there was a library that included both!  I decided to try it.

Custom Library Contents in Windows 7 Right clicking in a blank spot in my libraries window gave me a New –> Library option.  Cool!  After giving my library a name (Programs) I found there was nothing inside, I went back and right clicked on my new library and chose Properties.  I was presented with a dialog that let me change a few things, such as adding folders the library should look into.  I added my two Program Files locations, closed the dialog, opened the library and viola!  There are all of my programs!  Very cool!

Custom Windows 7 Library OptionsOne thing I will briefly note, if this library is for a type of files that you will be actually saving files into, you can select the folder that acts as the default location to save files.  That way when you are in an application and you choose to save something, you can just click on the library and it will save in the default folder.  That’s not something you’re likely to do with programs, but there are other file types.  Another library I have added, for example, is Source Code.

Customized Windows 7 Library They only thing that was disappointing at this point, was the fact that there was no option to assign a custom icon.  I did a quick search on Bing (I did a quick Google on Bing?) and found this guide regarding custom libraries.  It explained that libraries are really just XML files located in the special folder at C:\Users\<User>\AppData\Roaming\Microsoft\Windows\Libraries with some data describing the library.  One of the elements you an add to the library is called <iconReference></iconReference> which simply takes a path to an .ico files.  It does note that for the best results a 256×256 icon should be used, or an icon with appropriate sizes all in one file; however, I found one at 128×128 for my programs and it worked fine.

Using Windows 7 with Multiple Gateways (Routers) and DHCP

Early last year we implemented a second Internet connection on our network.  We wanted to make it as easy as possible to switch between the two if the primary connection went down.  We are on a Windows domain and use DHCP from one of our domain controllers so it was easy to implement the 003 Router scope option with the two gateways and it worked great!

According to RFC2131 and the DHCP Options and BOOTP Vendor Extensions;

The router option specifies a list of IP addresses for routers on the client’s subnet.  Routers SHOULD be listed in order of preference.

That last bit was the key for working in our situation.  Our Windows XP clients grabbed the multiple gateway addresses and modified the routing table like this:

Active Routes: 
Network Destination  Netmask       Gateway    Interface  Metric

Both entries have the metric of 20, which was dynamically assigned by windows based on the link speed, the first entry is the one that was used.

We recently began testing Windows 7 in our environment.  We are fairly happy with most of the new features, performance and the overall experience in the new OS.  One thing that, so far, has been a great improvement is the new network stack.  With Vista, there were several issues including problems with unexpected freezes while network requests are made and problems with notebooks when trying to close the lid.  In Windows 7 most of those issues seem to have went away.

One minor issue that we did run across seems to be a bug, in my opinion.  When our Windows 7 clients processed the same DHCP requests as our XP clients, the routing table looked like this:

Active Routes:
Network Destination  Netmask       Gateway    Interface  Metric

Very similar results, just slightly modified metric which I can only assume is due to an updated algorithm for calculating the dynamic metric.  The only problem is that the second entry was being used as the default gateway.  We verified this on multiple Windows 7 clients.  It seems like it goes against he “order of preference” bit of the RFC.

It took quite a while and a lot of research, but I found out that Microsoft implements a vendor specific extension, 003 Microsoft Default Router Metric Base option.  The documentation for this value reads:

This value is a specified router metric base to be used for all default gateway routes used at Windows 2000 DHCP-enabled client computers.

This value can be assigned as an integer cost metric ranging from 1 through 9,999. It is used in calculating the fastest, most reliable, and least expensive routes. If a value is not specified, a default of either one (1) or the currently set interface-specific metric is used.

This is not very specific and for a while I did not think it would apply different metrics, but rather the same metric to all of the values in the 003 Router option.  I decided to give it a try regardless of my doubts and it worked!  Now, my XP route table looks like this:

Active Routes:
Network Destination  Netmask       Gateway    Interface  Metric

And my Windows 7 route tables looks like this:

Active Routes:
Network Destination  Netmask       Gateway    Interface  Metric

It is still disappointing that the DHCP routing options seems to be broken in Windows 7 (IMHO), and I am sure there will be plenty of people having similar problems when they begin rolling out Windows 7 clients in their environments.  Hopefully this article will save someone a little time trying to configure their Windows 7 clients to use multiple gateways.

Fixing Windows Update on Windows XP

On the 4/19 the virus software we use falsely detected the system file wmiprvse.exe as a virus/malware threat.  The specific detection reported the file as Backdoor.Win32.Agent.afqs.  This happened on at least three of our workstations.  Some research on the web shows that more than one virus company had the same problem at around the same time which makes me wonder what happened.

While we were able to recover the file, some things just weren’t right.  The biggest problem ended up being with Windows Update.  When going to the site, it would simply hang on the part where it was checking your system for updates.

Investigation turned up mismatched versions of several of the wmi…. family of components.  Presumabl this was due to an incorrect file being restored by the system after the false positive event.  Trying to get it matched up correctly by had turned out to be problematic at best.

Finally I ran across an obscure post (sorry, I no longer have the link) where someone claimed that reinstalling a certain security patch from Microsoft fixed his problem.  After going through the re-installation of this patch on the first affected machine, it indeed worked!

The post referred to the MS09-12 securyt bulletin from Microsoft.  Most of the page refered to using Microsoft or Windows update to install the patch, which of course was not possible.  I was able to track down the direct download link for the file and I thought I would post it here for posterity.

Aessential Android Apps

android Now that I’ve been using my Android powered T-Moble G1 for several weeks, I thought it would be a good idea to share some of the applications that I find essential.  They range from true productivity to mindless time sucks, so take each as it is intended!

TouchDown for Android and Exchange

This is a great application giving access to my company Exchange server.  The UI and feature set is very nice.  I have access to my inbox, calendar and contacts.  It also has the ability to get to my other private folders.

The folks at NitroDesk have done a nice job of keeping the UI familiar for both Android and Outlook users.  It will, if you configure it properly work in the background and integrates with the standard Android notification system.

TouchDown seems to be developing fairly quickly and their team is quite responsive to questions via email.


This is a great application that helps you keep your installed apps up to date.  It checks multiple sources to ensure your applications are running at the latest release and gives you an easy shortcut to update them if it finds that they are not.

The Weather Channel

This is a nicely done, good looking weather app.  Not only does it give you the standard current conditions and forecasts, you can also download the latest Weather Channel video for your area and it integrates with maps to show you local weather stations and their reported conditions.

Shazam Shazam

This one is just cool.  So you’re out and about town one day, maybe riding with a buddy in his/her car.  The radio is playing some random music station when a song comes on that you want to know more about.  You whip out your G1 and fire up Shazam and let it listen to the song for a few seconds.  It goes and figures out what the song is, the artist and even lets you look it up on Amazon or search YouTube for videos.  I still get giddy when it tells me about some song that I had no idea what it was.  Wicked!

Power Manager

Let’s face it, the battery life on the G1 isn’t the greatest.  This little app gives you power profiles that will let you switch quickly and will even apply them when circumstances dictate.  Out of the box, for example, when your battery drops below 30% it turns off your WiFi and GPS automatically and shortens the time before the screen dims when inactive.  As a side-benefit, it also gives you quick access to toggle your WiFi, GPS, cell tower locations and bluetooth.  It’s a must have!


Ok, so this is a total time waster.  I don’t know what it is about solitaire, but it is a great way to spend that time in a waiting room.  This one includes Klondike, Spider and Freecell.

Honorable Mentions

There are quite a few more that I”ve installed and many that I use fairly often, but those above are the ones that I find I really would miss if they weren’t there.  Here they are in no particular order:

Do you have any favorite applications not listed here?  Let me know what they are and why, I’m always looking for new ones!

The truth about the T-Mobile G1 Android powered phone.

In a word (or two)…it rocks!

Recently I wrote about the initial unboxing of the twin G1’s my wife and I purchased.  I have not had it for a little over a week and a half so I thought it was time to share some of my thoughts on the experience so far.

The User Interface

image The UI is fairly intuitive.  As I stated in my previous post, my wife never had to open the Getting Started book.  That was fabulous.  The sliding and scrolling actions seem very smooth and natural.  I really like that.

I like having a home screen that is easily customizable.  Moving icons and widgets around is as easy as a tap ‘n hold.  Additional feedback is given via a brief vibration when the item is ready to move.

The notification system is great.  Icons appearing in the top that expand with a quick drag to see the details is a much better system than I was use to with Windows Mobile.


Getting my Gmail settings going was easy.  Now I can get to my mail or calendar with 1 icon tap, and the interface for Gmail is based on the web version complete with threads and labels.  Very nice!

Contacts also come from Gmail.  This was a bit of a struggle at first.  Most of my Gmail contacts were still in the suggested contacts state which meant I had some work to do in order to get them into my phone properly.  In addition, most did not have phone numbers associated with them and I am afraid I am a ways off from making that happen.  I am a little gun-shy about importing them from my SIM card as I feel this might create a bunch of duplicate entries that I would have to go back to correct, but I will admit I have not tried it yet.


image For the most part things are very easy to do.  Making calls, sending text, etc.  The one thing I have noticed that is a bit of a drawback comes when you want to change your settings.  Most items are accessed through the settings menu, so changing your ringer profile, toggling WiFi or Bluetooth, etc…  Fortunately, there are some very nice, free apps that put these items into one easy place.  It would have been nice out of the box, but the solution wasn’t difficult.

The battery life is ok considering everything it does and the amount of use I’ve been putting it through.  Watching videos, using the GPS with Google Maps in street view (and compass mode!), browsing the web via WiFi.  These things tend to drain the battery so you can’t expect too much.  I’m charging it about once a day with a 24 hour usage bringing me between 25% and 60% of remaining life.  Not terrible by any means.

YouTube.  Wow, this is very cool!  I have watched many videos, used search and went into the popular categories.  Over WiFi the quality is great, and even using the EDGE network (we get 3G in March) the video performance is more than fair.  I did not have high hopes for the EDGE scenario; however it looks like they scale the quality down to a level that allows the stream to work with the slower network, yet it is still quite viewable.

The Android Market

image There are a lot of cool applications, and many more that are not so cool, available in the market.  I’ve personally sampled close to a hundred already and I’ve narrowed my current install set to around 20-25 that I use.  The installer and uninstaller seems to work well.  I haven’t run into any problems yet, although I’ve heard that some people have had issues.

Some of the applications fill a definite hole in the out-of-the-box UI, but as stated earlier, they are fairly easy to find and install.  Others are nice add-ons that can help in certain situations, and still more are great time wasters 😀

Here is a list of some of my favorites:

  • aTrackDog – This helps you stay apprised of updates to your other installed applications.  – Must have!
  • Power Manager – Has automated, customizable profiles for different power situations.  I like the way it turns off my Wi-Fi if my battery level drops below 30%.
  • aSettings – This app puts most of the toggles you need (WiFi, Bluetooth, Ringer profile, GPS…) on 1 screen.  I set up a home screen shortcut to it.
  • Scoreboard – Sport score update application written by the Google folks.  Does a very nice job.
  • ConnectBot – A little ssh client used to connect to linux boxes.
  • PhoneFlix – Allows management of your Netflix queue from your phone.
  • Ringdroid – A nice application for creating ring tones from your MP3 files.  It lets you choose the portion of the song to save out as a ringtone file.
  • The Schwartz Unleashed – A total time-waster, light-saber application, but very cool!
  • The Weather Channel – Exactly what it sounds like, get current conditions and forecasts.  Even does videos.
  • Twidoid – For all your Twitter needs.
  • QuickPedia – Mobile interface for Wikipedia.  It includes nice formatting of the articles.
  • wpToGo – Nice blogger client if you happen to have a WordPress blog.


I am very happy with the phone.  My wife seems to really like it as well.  So far things have gone smooth and the decision seems to be a good one.  My overall opinion is that it is a good phone and if you are in the market for something like this, I would recommend it.

I Am Android

image The cell phone I’ve used for the past year and a half finally gave up the ghost.  I was using an HTC P4300, one from the touch screen family of HTC phones.  For the most part, it was OK as a phone platform; however, the Windows Mobile 5 operating system did have it’s issues.  I believe that I had to hard reset it to factory defaults and reinstall and configure my system 4 or 5 times during it’s life span.  That’s not terrible for someone in the tech industry, but your average phone user would probably find it irritating.

The phone recently went into the mode where it decides to start rebooting itself continually until it is plugged in to its power source making it utterly unusable, so it was time to start shopping.

I looked at some of the comparable upgrade options in the HTC, WinMo family.  There were some promising modes, but alas my carrier only had 1, and it was roughly 8-10 months old.  Considering the price tag approaching $350 USD. I decided that it was bit more than I really wanted to spend.

My options were to move to the Crack…er…BlackBerry.  I’ve never really like them so other options simply did not have the capabilities I wanted and needed.

imageOn to another carrier!  T-Mobile has the G1 (on the HTC Dream) running the Linux based Android system.  Here is a platform that has most of what I need and I have the ability to write my own applications for it, as I did with Windows Mobile.  I decided it was time for a switch.

At the same time my wife’s phone has been giving her fits.  She was ready for something new as well.  At first, all she wanted was a phone; however, the more we talked the more we came to realize that she really wanted more than that.  One of her highest priorities was the ability to easily get to her GMail account from her handset so we decided to get her a G1 as well.

I must admit that I was a bit worried.  I’d read some reviews that knock the so called “Google Phone” for not having a UI as polished as the iPhone.  While my wife is more tech-savvy than many that are not part of the tech sector, I did not want her to struggle with her telephone.

After talking it through, we went ahead with the order.  Due to the demand, the phones were not in stock in the store so we had to wait, anxiously , for them to arrive.

Our new G1’s arrived by UPS on a cold Tuesday evening.  After charging them up and flipping through the getting started guide to make sure it was easy to follow, I handed the guide and phone to my wife and grabbed mine to start setting it up and exploring the Android Market.

45 minutes later, from the other side of the couch, I heard a sound that brought me back to my youth.  It was the familiar song denoted the start of a game of Pac-Man.  I had seen it in the app market, so I had to laugh a bit and ask my wife what was going on.

Me: “Wife, what’cha got there?”

Wife: “shhh…oh..oh!!!! Dang it!” <followed by the bwoop bwoop of Pac-Man dying>

Wife: “I downloaded Pac-Man, this is SO COOL!”

Me: “Good, so you’re feeling OK with the phone?”

Wife: “Yeah, it’s pretty cool.”

Me: “Did you get your GMail set up?”

Wife: “Yeah, and my calendar is there too.”

Me: “Great!”

Wife: “Yeah”…pauses…”You know, It says a lot about a product when you are able to set everything up you want to without cracking open the book at all.”

Epic win for the Android in my opinion.  Thanks Google & T1!