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 I fixed Visual Studio crashing when opening XAML (WPF) files

For the second time, Visual Studio 2008 began crashing when double clicking on a XAML file.  In this case, the crash was spectacularly underwhelming.  No error message, blue screen or other indication of something horrible happing.  Visual Studio would simply go a way, or “blink out” as I’ve seen it referred to.

After much searching I was able to determine that the PowerCommands for Visual Studio 2008 extension was somehow involved in the problem.  I tried quite a few different solutions including adding a dependantAssembly reference in my Visual Studio configuration, doing a clean solution then rebuilding the project.  Up to that point the only thing that worked was uninstalling the extension.  Reinstalling afterwards would cause the problem to return.

Working without PowerCommands was an option I did not want to consider.  Many times each day I would use functions such as “Open Command Prompt” which fires up cmd.exe starting in the directory of the file or folder selected in the solution explorer or “Open Containing Folder” on a file, just to mention a couple.  It was looking like that was going to be the only solution, I was bummed.

I decided to check with the source a bit further.  I looked through their issue list and the top voted issue was VS 2008 crashes when adjusting toolbox items.  Reading the description did not give me a lot of hope as it dealt with a problem when the toolbox items were adjusted.  It also included an actual error which was lacking in my case.

Among the comments to the above issue, I found the suggestion to run the command “ngen /delete *” (without the quotes) from a Visual Studio 2008 command prompt.  Ngen is the native image generator which creates native images from managed assemblies and installs a native image cache on a computer, which is a reserved area of the global assembly cache.

Wow, that sounds important, and I’m suppose to delete * (star)?  Ok….I was desperate and I did it before investigating what it meant.  Dangerous, I know, I know, but as I said I was desperate!

It worked.   Nothing seemed to break…and it worked.  Ok, off we go!  Wait, time to investigate….just in case problems start cropping up later.

ngen-help Running ngen /? from the command prompt yielded no information, not a mention of the /delete switch.  In my experience, when a command line utility fails to mention an argument that clearly did something, this is an argument that should only be used with full knowledge of what it does.  Now I started to get nervous!

I did a quick Google Search and was lead to the MSDN documentation for ngen.  It seems that my little command deleted all native images in the native image cache.  Hmm….that sounds bad.  Fortunately, a little further down the page the following information was also present.


This made me feel a little better.  The assemblies were still there, simply not the native images for them.  Native images simply cause the applications or assemblies to start up a bit faster.  With today’s hardware, I don’t know that I’ll even notice a difference, or if I do, it will be worth it to keep PowerCommands and get rid of the problem.

If this behavior resurfaces, I will do a little more investigation by using the /show argument to find out what native images are installed.  Then I will started deleting them one at a time to find the culprit.  My guess is that one of the native images somehow became corrupted, or the configuration for it got messed up or something like that.  Perhaps finding the culprit will aid in the resolution of the issue that this wonderful extension is experiencing by, if the Google results are any indication, a fair number of developers.

My Adventures Installing mono 2.0 on CentOS 4 to work with apache via mod_mono

Apparently the good folks over at the mono project decided to discontinue binary packages for the Red Hat line of linux distributions.  It’s a shame in a way, there are a lot of those installation out there, so it would be nice to keep things updated through yum or apt-install or rhupdate, etc..

On the up side, installing from source has never been easier.  In the past I have went through many hours of trying to get the right versions of different libraries that were needed.  With the official release of 2.0 it seems much better.  I thought I would share the steps that I went through.

Disclaimer: This worked on a fairly fresh install of CentOS 4.7.  I have not tried it on 5.x, nor on any other flavor of linux (SUSE, Ubuntu, etc..) so your mileage may vary.

At the time of the install (and this writing) the current mono stable version is 2.0.1 so all references will be to that version.  Here are the steps that I went through.


Always be prepared – Boy Scouts motto…

In rooting around the web I did find a few helpful pointers.  First, make sure you have gcc installed.  Now this is one of those duh pieces of information, but in the fairness of completeness I thought I would mention it. (Note: If you do not have gcc or bison, install them! Credit The_Assimilator’s comment)

# yum install gcc-c++
# yum install bison
Next I installed the httpd-devel package.  I had read (will find the link later) that it helps some of the installation down the line.  In my case I just use yum to install it. (Note:  httpd-devel package is required by the mod_mono compile if apxs (Apache Extension Tool) is not on your machine. credit to The_Assimilator’s comment)
yum install httpd-devel

You may also require the glib-2.0 libraries (thanks to Michael Walsh for that bit).  If you receive the error “Package glib-2.0 was not found in the pkg-config search path” you can install it via yum as well.

yum install glib2-devel

The Main Dance

Next comes the meat of the installation.  First, I downloaded the necessary source packages.  I simply used wget to snag the core mono package, xsp (mono web server) and mod_mono (apache integration).


Next we install the mono core

tar -vxjf mono-2.0.1.tar.bz2
cd mono-2.0.1
make install
cd ..

Next comes xsp

tar -vxjf
cd xsp-2.0
make install
cd ..

At this point I recevied an error (I believe it was in the make process) that the compiler could not find the file dotnet.pc.  I found that it was indeed on my system so I simply had to export the path and then finsih the compile.

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
make install

Note: Make sure the file dotnet.pc is in that location.  If not, adjust the path above.

Finally we install mod_mono

tar -vxjf mod_mono-2.0.tar.bz2
cd mod_mono-2.0
make install

There, easy huh?


You may want to verify a few thigns to make sure the configuration is ready to rock.  In my case, I am keeping the mono configuration in a separate file for sanity sake.  You can do that or put it all in your httpd.conf, it’s up to you.

<IfModule !mod_mono.c>
    LoadModule mono_module /usr/lib/httpd/modules/
    AddType application/x-asp-net .aspx
    AddType application/x-asp-net .asmx
    AddType application/x-asp-net .ashx
    AddType application/x-asp-net .asax
    AddType application/x-asp-net .ascx
    AddType application/x-asp-net .soap
    AddType application/x-asp-net .rem
    AddType application/x-asp-net .axd
    AddType application/x-asp-net .cs
    AddType application/x-asp-net .config
    AddType application/x-asp-net .Config
    AddType application/x-asp-net .dll
    DirectoryIndex index.aspx
    DirectoryIndex Default.aspx
    DirectoryIndex default.aspx
That was it.  I hope that helps!

Visual Studio 2008 RTM

Microsoft shipped Visual Studio 2008 to manufacturing today. According to some it has become available for download on the MSDN subscriber site, but only the Team Suite edition. Since we do not have the “über” subscription (I believe ours is one step below that) we’ll have to wait for MS to make the professional edition available.

Update: I finally was able to start downloading.  Apparently MS decided to use a different distribution method (Akami?) to get over the initial rush, or at least that is my guess on the matter and it is purely my own speculation.  The download location was not the normal MSDN subscriber downloads area.  In addition, I had to install a new download manager and of course allow popups from before I could get it started, but now it’s on is own merry way to my computer!  It’s coming down at a good clip too, ,about 570 KB/sec so if things remain as they are I should have it within a couple of hours.  😀

Good luck to anyone else, hopefully grabbing this one 🙂

Viewstate – Search Engine Update

I’ve been out of town for a bit so I’ve been behind on checking the test Dave has been running.  If you haven’t read the original concept, please do so.

2007-06-24_arkliodetest.pngToday I noticed that page 4, one with a large viewstate, is showing up #1 at Google.  To my knowledge, this is the first time one of the pages has received the #1 spot.

I’m not sure why the other pages are not showing up.  Perhaps they are being marked as duplicate content or something, but it is interesting that the page with Viewstate is the one ranking right now.

Viewstate Effects on Search Engines – Part 2

It has been 12 days since Dave put up his viewstate test pages with the keyword Arkliode.  Watching Google each weekday has brought about a few interesting thoughts

  1. Initially the index page with a link to each of his tests ranked #1.  This went on for most of last week.
  2. One of the tests ranked under the index page when you click on the “View similar results” link on the initial Google search.
  3. My original post was ranking #2 for most of last week.  It only had the word “arkliode” once in one of the comments.
  4. Arkliode results snapshot on 6/11/2007This morning, my original post shows up #1.  Yes, that is the post with the word only displayed once in a comment.
  5. Google gives more weight to blog posts.  This has been generally accepted for quite a while.  That explains the change in #1 ranking.
  6. Incoming links play a large part in the role.  I am attributing that reasoning to the drop of the one page that was returning in the results.  The incoming links simply go to the index page.
  7. Duplicate content has been assumed to have a negative impact.  Since most of the test content pages have the same or very similar content, I am theorizing that Google is recognizing them as duplicate and since the only links going to them are from the index page.

The next question is, how do we begin to make the test valid?  I suppose we would have to post the different pages on separate sites to try to get a better idea, yet the popularity and ranking of the sites would undoubtedly play into the ranking.

Dave has changed things up a bit, which might account for the changes over the weekend. Should people begin linking to the pages on their sites to see if indexing begins to happen?  That’s what Dave did.  Here are the links to the pages.

I will check back in later this week or early next week.  I’m sure Dave will have at least one update in that time-frame as well.

Back to writing, craziness calming, TFS and a test passed

Wow, it’s been a busy few weeks.  Seems like work has kept me more focused than normal with certain work items needed.  I apologize to my loyal readers for the lack of content recently.

I have had my first real look at Microsoft Team Foundation Server and I must say I am not impressed.  It looks like it has some nice features, however I would not say that it is worth the price of admission.  Licensing seems a bit high and the preferred method of using it via Visual Studio is a bit clunky.  The add-in (Team Explorer) works well enough, but it is plain and seems to bloat VS as many add-ins do.  If I am going to settle for reduced performance in my development IDE I would expect more out of it.   At this time I am looking into SharpForge, a somewhat new and growing open source project designed to perform some of the functionality of TFS or SourceForge.  The web interface from TeamPlain, recently acquired by Microsoft, is not bad.  I will admit that I am a bit predisposed against the entire system since it is based on Microsoft SharePonit Portal Server.  I have yet to be convinced that the platform is desirable enough to move to.

In the mean time, I also passed another test on my way to MCSD and then MCPD.  70-315, Developing Web Applications with Visual C#.NET is complete.  On to the next one!  Target date is set for 3 weeks, although budget may push it to next month.  I hate tax time.  😉