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=2.0.0.0, 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.
It 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.
I 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!
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
- Initially the index page with a link to each of his tests ranked #1. This went on for most of last week.
- One of the tests ranked under the index page when you click on the “View similar results” link on the initial Google search.
- My original post was ranking #2 for most of last week. It only had the word “arkliode” once in one of the comments.
This morning, my original post shows up #1. Yes, that is the post with the word only displayed once in a comment.- Google gives more weight to blog posts. This has been generally accepted for quite a while. That explains the change in #1 ranking.
- 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.
- 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.
Cheers!
Troubleshooting Memory Leaks in .NET
OK, you’re still here. You are a brave soul if you’ve stuck around after a title like that, or else you are desperate! That is exactly where I found myself over the last two days.
A product we are currently working on has a process that, well, processes a lot. It goes through several different data gathering, manipulation, saving and printing operations. The end result of this process is a print job that takes about an hour and produces about 1000 printed pages.
For the development we normally sent the jobs to a PDF printer or simply had it stop after printing 20 or 30 pages. Finally the time came to give this a real test, a complete dry run!
*poof*
I know what you’re thinking, “you should have done that in Dev at least once!” You are right of course, however sometimes we let things slip due to schedules and pressure. Lesson learned, I hope!
It appeared as though there was a memory leak causing the application to crash. Monitoring the memory usage with Process Explorer confirmed this to be the case. Now to the task of tracking it down.
I must admit that I have never had a leak like this one. After some initial code reviews there were a few places where we were able to determine the potential for problems. Implementing code to fix these “phantom menaces” were not successful. Now it was time to really dig in. The downside was, I did not know how to dig, and I didn’t have a shovel.
After some searching around on Google, I ran across Finding .NET Memory Leaks by Phil Write. It was not the easiest thing to find, but it was well worth the time. Phil goes step by step through using sos.exe (Son of Strike) debugging extensions. He explained the basis of how to track down what you think the problem is. Unfortunately the problem was not that easy to find. I ended up doing comparisons of the output of !dumpheap -stat from very early in the process and another dump from much later on down the line. It was a tedious exercise, but a necessary one. Finally I happened upon an object that had a large jump in it’s count between the two samples. Now I had a place to start! Using Phil’s instructions again I was able to find out what was holding on to a reference and implement a fix. It also lead me to a second leak that we did not know existed and had been around for quite a while. It turned out that the first leak that we fixed would not have been a problem if the other one had been behaving properly.
This is a good example of why bugs can be good. The second memory leak will be taken care of within the next day or two and the product will be that much better for it.
Success!
Thanks Phil for such a wonderful and simple to understand article!
Review – VI emulation for Microsoft products
If you, like me, find yourself using Microsoft products for your daily operations (or are forced to as some) yet you have a background in which you have a comfort level using vi, the *nix based text editor.
The percentage of people that prefer to use vi is probably small compared to the people using notepad, emacs or pico or other simple editor. It takes a certain amount of masochism to plow through the various commands used to move around, edit, replace etc.. inside of vi but for those of you that have that trait as I, vi gives you a productivity increase that is unparalleled, in my opinion.
Now, if only we had that in Windows!
Fortunately we do. For several years now the vi project has had a Windows text editor which I use. It is a very good implementation within the Windows environment. For editing text based files where you do not need any further functionality, I highly recommend it.
Now, on to the fun stuff!
Jon at NGEDIT Software has a few products that have made my life a lot easier. It falls under the heading of VIEmu, the vi-vim editor emulation for Visual Studio, Word, Outlook and SQL Server. I can tell you that, after downloading the Visual Studio trial and running with it for a few weeks, I have purchased all 3 (Word and Outlook are combined in 1 package) products. They are wonderful!
You should not expect 100% vi-vim compatibility, there are some things that just do not work quite the same, however most of the basic and much of the advanced functionality is available. There are a few quirks as well, such as the need to use Shift+Esc instead of just Esc to get out of some modes, but they are workable once you get use to them.
I should say that this review was not sponsored in any way, nor did Jon or anyone at NGEDIT Software know about my writing of this before publication, I do believe in full discloser of sources and sponsorship when posting (thanks Robert Scoble for the inspiration), this is purely a fan-driven review of these products.
The Word and Outlook version is a bit young, only version 1.0, however the Visual Studio product has been around a while and the SQL product just a bit less time. So far all have been performing well and my productivity has increased, at least I believe it has.
If you are/were a vi-vim junkie living in a Microsoft world, I urge you to head over and try it out for yourself. I think you will be happily comfortable again within the embrace of vi-vim!
Viewstate Helper from Binary Fortress Software
Wow, I am going to be accused of becoming a Scott Hanselman sycophant if he keeps up the pace of the great posts he’s had lately! In his most recent post (as of the time of this writing) he points out a piece of software recently discovered. After reading through his review I had to try it out for myself. It is the ASP.NET Viewstate Helper from Binary Fortress Software. This is a very nice tool!
It sits in the background monitoring the HTTP conversations that IE has. It presents a historical list of the pages visted along with some stats about the size of the page and the Viewstate, if it has one. It also allows you to double click on a page to see the decompiled version of the Viewstate.
It tries to display the viewstate in a tree view, although I have found it doesn’t always work. It does give you a text representation that will get you what you need although you may have to search through it a bit if the viewstate is complex.
The one downside I have found so far is that it does not work with Firefox, or at least I have not happened upon how to do it. For the time, I can live with that. The information that it provided on a few of the sites we’ve created has already been eye-opening.
Reflector for .NET 5 is available
Lutz had released version 5 of Reflector. If you are a .NET programer and you do not use it, get it now! Also head over to Codeplex to get some of the excellent add-ins for Reflector.
Brian Scott releases Cropper 1.9
Cropper is a nice little screen capture utility written in C#. It has a fairly nice plug-in interface allowing other developers to write extensions. An example of one that I use is the Flickr plug-in to automatically upload captures to my account. Very slick! Another plug-in also allows you to save animated GIF’s! That is one feature I have not seen in another screen capture utility.
Cropper is a fairly simple capture utility lacking some of the features of commercially available products. Another utility that I use is the FastStone Capture which has the ability to edit the captures (crop, re-size, add call-outs, etc…) before saving. That is the only feature that I can think of that I miss in Cropper to make it my full-time capture utility.
I started work on a plug-in to add the editing functionality with version 1.8 but never had time to pursue it. I ran into enough roadblocks that I shelved it. I may dig that out again to see how it may work with the enhanced plug-in interface. There are many things about Cropper that would make it a better choice, in my opinion. The keyboard ability to move the selection around is very nice.
Overall, FastStone is probably my day-to-day capture program, but I’ll be keeping an eye on Cropper. If some of those features are added I will likely switch its role to my normal capture utility rather than the one I use when I need to upload to Flickr.
UPDATE: I realized that I was using version 4.7 of FastStone Capture yet the current stable version is 5.2. After installing it I found some great new features, including different edging options. There is also a portable version! I am currently using the USB menu system from portableapps.com. I simply downloaded the FastStone Capture portable version, extracted the folder inside the zip file to the PortableApps folder (you want the folder, not just the files), refreshed the PortableApps menu and viola! It works great!
In Search Of…
A solution! Since I have yet to find one, I’ll settle for a little rant.
<rant>
If you are a developer using the Visual Studio 2005 IDE you may have run across the infamous “unable to copy file…..” error when trying to compile your solution. If you work on anything somewhat complex with many projects in one solution, you may have experienced this a lot.
Formerly I put the blame on Visual Studio itself. I have been informed that it is not a problem with VS, but rather an issue with the .NET Frameowork. I’ve ready many posts about the issue, but have yet to find anything that fixes the problem. It wouldn’t be so bad, however the project I’m currently working on has 18 projects in the solution and reloading VS every time this happens is a real productivity killer!
</rant>
Whew, now that I’ve got that off my chest…if anyone finds a solution that works, please leave me a comment about it!