Brendan Enrick

Daily Software Development

Embedded Resources not so painful anymore.

    Well after a frustrating time trying to figure out how to make embedded resources work, I finally understand. This makes everything much easier. As some of you may know I have been working on a content management tool. (This is not a full blown content management system) Since it is designed to be portable to existing ASP.NET web sites, it is just a dll file. Even though it uses a couple of images, I don’t want anyone to have to copy image files just to get the app working correctly.

    To accomplish this I decided to use embedded resources, something I had never done before. Starting out I fumbled a lot trying to figure out how to display these, bad idea. Well I started googling for a solution to my problem, and I tried doing what Microsoft said to do. Following what they said to do got me nowhere, and left me a bit more confused. The site makes many assumptions about what I all ready know. Since I did not know these things, I took some guesses. Sadly incorrect ones. I think the authors of those resources need to learn the value of a hyperlink. It would allow them to reference old material so I could learn what they assume I know.

    After reading that I had a better reference to start googling. I started looking for the GetWebResourceUrl method, and this led me to other web sites, which had some better explainations. At first I went to an article on codeproject explaining how to access embedded image resources. This was much better than the previous one I read, but I still could not get this one working right. My example didn’t quite fit with what they did, and they didn’t explain each part of the process.The problem is that even if I had incorrect code in my file, GetWebResourceUrl still returned a url that looked like it was supposed to. Again I needed to find something to get this working, or I would have to go back and start writing a lot of code I did not want to write.

    So I tried another link I found on google, and this article on Embedding Resources in ASP.NET 2.0 Assemblies explained to me very well how to get my embedded resources working. It explicitly told me where each part of code belonged It mentioned some specifics I might need that were not even part of that example. Not only that but it had more than one type of embedded resource that it accessed. If you are ever trying to use embedded resources I recommend it, but I suggest reading this article first. I may have to start reading more articled written by Mark Hines. If you are interested in this topic, I suggest reading this article as well Embedding Resources in ASP.NET 2.0 Assemblies - Part 2.

Caching made easier with a cache manager

   I recently added caching to my Content Management System. Since I am no caching expert I wanted to make sure I had created the functionality that I wanted to make. I wanted to ensure durations were as I expected, and wanted to make sure that items were cached when they should be and removed when they shouldn’t be cached anymore. I could have changed the program to debugging mode and debugged the code. I could also have added code to check and see the values of the cache object at certain times, but I found a much easier solution.

   I found that by adding this Cache Manager plug-in to my site I was able to quickly and easily check at any moment what was in the cache. All it took to add this to my site was copying this file into my bin folder, and copying a line of code into my web.config file. Since I was just using this while debugging the application there was no need to worry about the optional security on the cache manager. When I was done setting up the caching, I simply removed the dll file and the line of code from my web.config file.

   I recommend checking out that cool little plug-in if you are doing any work with caching. I plan to use that tool any time I am working with caching on any ASP.NET web site. I like things that make my job easier.