<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-3277088726597339855</id><updated>2009-11-13T06:04:42.533-05:00</updated><title type='text'>Berke</title><subtitle type='html'>Various Ramblings of a .Net Web Developer</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default?start-index=26&amp;max-results=25'/><author><name>Josh Berke</name><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>71</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-3922630555599384534</id><published>2009-10-14T09:43:00.000-04:00</published><updated>2009-10-14T09:43:59.008-04:00</updated><title type='text'>Google &amp; MVPs</title><content type='html'>For those who don't know who &lt;a href="http://meta.stackoverflow.com/questions/9134/jon-skeet-facts"&gt;Jon Skeet&lt;/a&gt; is, he is an excellent contributor to the C# community, through his daily answering of questions on Stack Overflow, to his many excellent articles and books. Jon recently &lt;a href="http://msmvps.com/blogs/jon_skeet/archive/2009/10/01/mvp-no-more.aspx"&gt;posted&lt;/a&gt; that his employer has asked him to turn down the MVP reward for this year.&lt;br /&gt;&lt;br /&gt;What employer wouldn't want their employees to be recognized as community leaders in Microsoft Technologies? Google for one, as they are Jon's current employer. Jon won't comment on why this is so it leaves us to speculate what the reasons might be. Even if there is a sensible reason for this the silence lets myself feel that this is due to the competition between the two companies. That has definitely soured my opinion about Google and its Management team.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-3922630555599384534?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/3922630555599384534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=3922630555599384534' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3922630555599384534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3922630555599384534'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/10/google-mvps.html' title='Google &amp; MVPs'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-1577976440165092687</id><published>2009-10-01T16:07:00.000-04:00</published><updated>2009-10-01T16:07:30.318-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><title type='text'>Just trust me!!</title><content type='html'>Today I was working with my intern, we are using DotNetNuke to run a marketing site so that our product team can go in and tweak some things. We have custom workflow in there, and a requirement that we want to save the results of the workflow into our own table so we can report on it latter. &lt;br /&gt;&lt;br /&gt;The workflow component has some facilities to do this, so he creates a table and a stored proc, and gives it a shot. He is instantly greated with a lovely error in the front end &lt;em&gt;Invalid Syntax Near xyz&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;I tell him that's not good, as it indicates a potential for a Sql injection attack. Fast forward three hours, and he is arguing with me that its safe, that it can't be injected, and demands I prove to him it can be done. &lt;br /&gt;&lt;br /&gt;Not wanting to take the time or effort to figure out the magic sequence, as this isn't something I do everyday (Contrary to popular belief, I don't sit around trying to hack). I tell him to trust me, parsing errors are easy to inject into. He doesn't buy it, and I can see he is going to be stubborn until I prove him wrong. &lt;br /&gt;&lt;br /&gt;Fast forward&amp;nbsp;ten minutes, and I found that injecting with this forms component was as simple as entering a string like the following for the last field: &lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;blockquote&gt;&lt;em&gt;injectComing' select * from aspnet_users--&lt;/em&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;/em&gt;Watching with profiler, we quickly saw three key events. First was a Batch Starting which looked something like this:&lt;br /&gt;&lt;blockquote&gt;exec myProc '','','','injectComing' select*from aspnet_users--';&lt;br /&gt;&lt;/blockquote&gt;Second was SQL Stmt Starting Event:&lt;br /&gt;&lt;blockquote&gt;exec myProc '','','','injectComing'&lt;/blockquote&gt;Third was another Sql Stmt Starting Event:&lt;br /&gt;&lt;blockquote&gt;select*from aspnet_users--';&lt;/blockquote&gt;Needless to say now he is working on a costume module so we can execute the Sql as a parameterized query and avoid all this ass ache. Moral of the story? While you shouldn't always trust everyone, you should trust your boss who has 10 more years of experience.&amp;nbsp;And if you don't you try and prove him wrong, don't demand&amp;nbsp;your boss to prove himself.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Gahh Interns!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-1577976440165092687?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/1577976440165092687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=1577976440165092687' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/1577976440165092687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/1577976440165092687'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/10/just-trust-me.html' title='Just trust me!!'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-4880345493218685795</id><published>2009-09-26T12:23:00.000-04:00</published><updated>2009-09-26T12:23:30.274-04:00</updated><title type='text'>Responsability of Third Party Control &amp; Blacklists</title><content type='html'>My intern just sent me a screen shot of a CAPTCHA from a site we are working. The CAPTCHA is generated by a third party control which we have no control over. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_x1o4p4pyxUQ/Sr4_UbykzzI/AAAAAAAAACs/y6qgON-7Sys/s1600-h/Capture.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_x1o4p4pyxUQ/Sr4_UbykzzI/AAAAAAAAACs/y6qgON-7Sys/s320/Capture.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;If you are a developer of third party controls which are sold to professional companies please take the effort to implement a blacklist of letter sequences that should not be allowed in CAPTCHAs. What are the odds of this happening probally preety small but had we lost a sale because of this....&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-4880345493218685795?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/4880345493218685795/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=4880345493218685795' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/4880345493218685795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/4880345493218685795'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/09/responsability-of-third-party-control.html' title='Responsability of Third Party Control &amp; Blacklists'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_x1o4p4pyxUQ/Sr4_UbykzzI/AAAAAAAAACs/y6qgON-7Sys/s72-c/Capture.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-2454164176071465622</id><published>2009-09-08T16:26:00.002-04:00</published><updated>2009-09-08T16:30:56.049-04:00</updated><title type='text'>Telerik Gives Back to the Community</title><content type='html'>While using &lt;a href="http://stackoverflow.com"&gt;StackOverflow &lt;/a&gt;a great site for asking questions to problems software developers face, I noticed an &lt;a href="https://www.telerik.com/registration-login/stackoverflowregistration.aspx?utm_source=StackOverflow&amp;amp;utm_medium=banner&amp;amp;utm_campaign=PointsPromo_September"&gt;advertisment from Telerik&lt;/a&gt;. They have decided to give any SO user who has over 10,000 reputation points a free developers license to their control suite.&lt;br /&gt;&lt;br /&gt;This is great to see a company see the value a site such as Stackoverflow provides, and to provide some recognition to the people who spend their time helping others by answering questions. Thanks again!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-2454164176071465622?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/2454164176071465622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=2454164176071465622' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/2454164176071465622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/2454164176071465622'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/09/telerik-gives-back-to-community.html' title='Telerik Gives Back to the Community'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-4335071326691931281</id><published>2009-08-26T16:28:00.006-04:00</published><updated>2009-08-27T12:46:03.282-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><title type='text'>Duration in RPC:Completed is Misleading</title><content type='html'>I discovered something today while troubleshooting a long running query today. We have a specific dialog in our application which in a specific case takes 60 seconds to open up. I fire up SQL Profiler and click run just to see the standard events and verify if this a DB issue or not.&lt;br /&gt;&lt;br /&gt;I find that there is a specific query which does take 60 seconds to run according to the RPC:Completed event (We are using SQL Server 2005). So I pull that query out and run it inside of SSMS, it completes in under a second. These are the issues I hate having to troubleshoot. So the first thing was to rule out our web application, so I create a little .net windows form app and I basically run this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="FONT-FAMILY: Courier New; BACKGROUND: #e1d5d7; COLOR: black; FONT-SIZE: 10pt"&gt;&lt;pre style="MARGIN: 0px"&gt;sqlCmd.Connection.Open();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; (&lt;span style="color:blue;"&gt;var&lt;/span&gt; reader = sqlCmd.ExecuteReader())&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;{&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;int&lt;/span&gt; i = 0;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;while&lt;/span&gt; (reader.Read())&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        i++;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(i.ToString());&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The query runs fine no issue. Now we are actually using nHibernate so I wanted to simulate us processing the result set. I add a small Thread.Sleep(5) (my result set has 1500 items in it so a small sleep duration is plenty). I run the query and wait about eight seconds.&lt;br /&gt;&lt;br /&gt;Then I go and look at SQL Profiler RPC:Completed (And Stmt:Completed events). The duration for the events is 8 seconds. Now I am asking myself if I opened a ticket with Microsoft burned a support incident for an nHibernate issue or not.&lt;br /&gt;&lt;br /&gt;The moral of the story? Well don't always trust what you think the tool is measuring. And if your interested, when I ran my queries loading the entities through nHibernate with the windows form, the query again completed extremly fast. So I am still hunting this one down.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I found and resolved the issue. It wasn't an issue with SQL but a configuration issue which caused the system to try and log to an invalid file thousands of times which slowed the system down.&lt;br /&gt;&lt;br /&gt;This is very eye-opening as one of my fundamental assumptions about SQL Profiler and how to interpret the results has been crushed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-4335071326691931281?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/4335071326691931281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=4335071326691931281' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/4335071326691931281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/4335071326691931281'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/08/duration-in-rpccompleted-is-misleading.html' title='Duration in RPC:Completed is Misleading'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-5916631185148833695</id><published>2009-07-14T10:23:00.002-04:00</published><updated>2009-07-14T10:59:46.977-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><title type='text'>Turning off ASP.Net's Unique ID Generation</title><content type='html'>One of the things I am not a fan of (but I understand why they have it), is the unique id generation for server side controls in ASP.Net. The unique Id generation allows the framework to ensure that all controls will have a unique client Id, allowing it avoid collisions.&lt;br /&gt;&lt;br /&gt;While this is great it does add a lot of complexity as you start to move away from the traditional ASP.Net Web Forms model. This complexity is one of the reasons this feature doesn't exist in &lt;a href="http://www.asp.net/mvc/"&gt;ASP.Net MVC&lt;/a&gt;. What are some of the issues with the unique id generation?&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;If you have javascript in your pages the controls are given a somewhat dynamic name, this leaves you with two options. Either you dynamically generate your javascript, or you can assume that you won't be moving the control, and can hard code the ID. The ID is based upon a concept of Naming Containers which is beyond the scope of this post. But essentially as long as you don't introduce new containers in the hierarchy the Id will always be the same.&lt;/li&gt;&lt;li&gt;If you want to use post a form to a non-web form page(or different page then the generating page), and want to make use form fields, the field names are associated to their unique id.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The first issue I have always solved by either generating the javascript dynamically in my user controls for example (A user control acts as a naming container and thus all controls in the user control will have it's unique id based on the user control's id). Or by just hard coding the value and hopping I don't change it. &lt;/p&gt;&lt;p&gt;During my latest round of enhancements to my current project I ran into a scenario where I felt I had to disable this unique id generation and couldn't find a workaround that didn't involve rewriting a ton of code. Let me give you some background on the scenario.&lt;/p&gt;&lt;p&gt;This site deals with types of documents, and allows the user to printout (or Email) various PDF files based on the document. There are currently roughly a dozen various printouts and emails which are generated, and the number is always growing. In order to streamline my code and simplify adding new types of printouts, I created a method of doing this which essentially is as follows:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;On the document's details page we have a second form, this form contains all the printing and email options. There are quite a few variations of options, and certain options depend on other options being set. &lt;/li&gt;&lt;li&gt;We preserve the last options used to printout the document, which are set at render time for the page. &lt;/li&gt;&lt;li&gt;The form is smart enough to know which type of printout it is doing and will either open a new window, or reuse the current window when doing a post.&lt;/li&gt;&lt;li&gt;This form posts to an ASP.Net Handler which based on the type of printout directs the request to what I call a print handler. The print handler will either execute (if its sending an email for example), or it might render a new page to let the user see a preview, or it might just generate a PDF for the user. &lt;/li&gt;&lt;li&gt;When generating PDF's we generate the Html and then use a &lt;a href="http://www.blogger.com/www.html-to-pdf.net"&gt;third party tool &lt;/a&gt;to convert it to Html.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It's actually a pretty slick mechanism and has streamlined a lot of the code. My new requirement is to enable printing from other pages then the Details page. At this point I have two choices. I can either duplicate a subset of my code to allow printing for just document types we need, or I can try and find a way to consolidate this printing framework to make it reusable. &lt;/p&gt;&lt;p&gt;I opted for the second option of course. So the first thing was to move all the markup, script and code behind outside of the details page into its own user control. A quick test showed that some basic functionality is there so I dropped the control onto my new page and things were looking good. This might be possible I thought.&lt;/p&gt;&lt;p&gt;Then I started doing a deeper more thorough testing (And I wish I had an automated unit test for this UI stuff but ah well It's on my ever growing to do list). I quickly found that all the Id's had changed, this messed with all the javscript which enables or disabled options based on what you've selected. &lt;/p&gt;&lt;p&gt;Well we can fix this one easily so I pick one of the controls, and modify the javascript so it is dynamically generated, and things are looking good again. So then I go and printout the most complex of the documents, this time paying close attention to it, and I noticed that none of the options that were set, were being honored. &lt;/p&gt;&lt;p&gt;The issue is the form fields changed so in the old version I was expecting to see a field with id of "printDescription" now it's coming out as "printOptions_printDescription". Furthermore when I drop it into a content page, which happens to user a master page which is also nested, the Id becomes a long mess. So now at this point how can I tell ASP.Net to not auto generate the Id's. I could write my own custom server side controls but that's a lot of work. I could get rid of the server side setting of options but to do that I would now have to either generate all the html dynamically, use code in the markup, or make a second call to get an json representation of the print options and set them on the client.&lt;/p&gt;&lt;p&gt;So let's get back to the original point of this post. I am going to turn off the Unique ID Generation. The first thing is this works if you have a naming container, which you can override properties on. A user control works perfectly, and since a user control doesnt render any markup by default it doesn't change the structure of the page. &lt;/p&gt;&lt;p&gt;I have found that by overriding the following properties results in the control's child control's from picking up the containers uniqueid and appending it.&lt;/p&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; UniqueID&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:#a31515;"&gt;""&lt;/span&gt;; }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Control&lt;/span&gt; NamingContainer&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;return&lt;/span&gt; &lt;span style="color:blue;"&gt;null&lt;/span&gt;;}&lt;br /&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:Red;font-weight:bold"&gt;Caution&lt;/span&gt;&lt;br/&gt;&lt;br /&gt;&lt;br /&gt;I have not tested this beyond my simple usage scenario. I do not know what would happen if these controls were used in a normal postback scenario, if they would be able to pickup their state from the form fields or not.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-5916631185148833695?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/5916631185148833695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=5916631185148833695' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5916631185148833695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5916631185148833695'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/07/turning-off-aspnets-unique-id.html' title='Turning off ASP.Net&apos;s Unique ID Generation'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-6933309354504807555</id><published>2009-06-24T10:04:00.003-04:00</published><updated>2009-06-24T10:11:19.228-04:00</updated><title type='text'>I need a vacation</title><content type='html'>So this morning I was thinking about some basic things we can do to speed up the download of our pages, including combining and minifying our JS / CSS files. I decided to go look at &lt;a href="http://www.julienlecomte.net/yuicompressor/"&gt;YuiCompressor&lt;/a&gt;, which is a minifier from Yahoo. &lt;br /&gt;&lt;br /&gt;I think to myself neat let me bookmark that and come back to it. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_x1o4p4pyxUQ/SkIz0M3YcqI/AAAAAAAAACk/yBwOetJlUIc/s1600-h/yuicompressorbookmark.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 161px;" src="http://1.bp.blogspot.com/_x1o4p4pyxUQ/SkIz0M3YcqI/AAAAAAAAACk/yBwOetJlUIc/s320/yuicompressorbookmark.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5350896279169299106" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I guess I had this same thought the last time I thought about the subject. Ugh!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-6933309354504807555?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/6933309354504807555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=6933309354504807555' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6933309354504807555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6933309354504807555'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/06/i-need-vacation.html' title='I need a vacation'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_x1o4p4pyxUQ/SkIz0M3YcqI/AAAAAAAAACk/yBwOetJlUIc/s72-c/yuicompressorbookmark.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-5082609809069075302</id><published>2009-06-08T15:47:00.004-04:00</published><updated>2009-06-08T17:00:32.953-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><title type='text'>How not to use a user control</title><content type='html'>I am in the middle of a nice refactoring session, changing a setup dialog, which allowed you to edit 4 types of email templates. Since the data was the same I had a user control which was then placed on four different tabs.&lt;br /&gt;&lt;br /&gt;We are going to tripple the number of types of emails that are going to be configured. So now my simple dialog of four tabs explodes into 12, and while I do not claim to be a UX expert by any means, and I am not able to design the latest slickest easiest to use interface; I can recognize a bad UI very easily.&lt;br /&gt;&lt;br /&gt;I have decided to use a drop downlist paradigm where the user selects from the drop down the template they are going to work with, and then we present them this information.&lt;br /&gt;&lt;br /&gt;During my refactoring I stripped out my tabs and added the drop down. I removed all but one instance of my user control. I have everything working except I'd like for drop down to line up better with the contents of the user control.&lt;br /&gt;&lt;br /&gt;The html that gets rendered is like this:&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;        Select a Template:&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;select&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;option&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;option&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;select&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:green;"&gt;&amp;lt;!--This table comes my user control --&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;table&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;tbody&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;tr&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                        Item 1:&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                        &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;input&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;tr&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;tbody&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;table&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The problem is the select template doesn't line up with the rest of the labels. This lead me to the ahhahh moment that lead to this post. I do not recommend doing this in production code. I think it makes the code very unreadable.&lt;br /&gt;&lt;br /&gt;Nothing says that the user control must render a valid html fragment. Using that to my advantage I modified the code so my aspx page looks like:&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;table&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;tr&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                    Select A Template:&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DropDownList&lt;/span&gt; &lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;="server"&lt;/span&gt; &lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;="DropDownList1"&lt;/span&gt; &lt;span style="color:red;"&gt;AutoPostBack&lt;/span&gt;&lt;span style="color:blue;"&gt;="true"&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt; &lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DropDownList&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;td&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;tr&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;croixUser&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;emailConfig&lt;/span&gt; &lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;="server"&lt;/span&gt;  &lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is basically my entire, I never close the table in the page, I do that in the user control. While we shouldn't be able to do this it makes sense that Microsoft hasn't wasted any energy in blocking this. If you want to shoot your own foot off with convoluted code go ahead. &lt;br /&gt;&lt;br /&gt;Now I must be off to refactor that user control to dev\null&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-5082609809069075302?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/5082609809069075302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=5082609809069075302' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5082609809069075302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5082609809069075302'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/06/how-not-to-use-user-control.html' title='How not to use a user control'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-4813371897287923802</id><published>2009-06-03T15:45:00.005-04:00</published><updated>2009-06-11T10:29:02.684-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Jquery 1.3.2 &amp; Intellisense in Visual Studio 2008</title><content type='html'>After following the &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx"&gt;directions&lt;/a&gt; to get intellisense working with the latest version of jquery, I ran into some issues.&lt;br /&gt;&lt;br /&gt;First I would get this error:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Error updating JScript IntelliSense: D:\Source\...\JS\jquery\jquery-1.3.2.js: Object doesn't support this property or method @ 18:9345&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The first problem is that the file which has the enhanced comments for intellisense is named jquery-1.3.2-vsdoc2.js. Visual Studio is looking for a *vsdoc.js. Make sure you rename the file to jquery-1.3.2-vsdoc.js.&lt;br /&gt;&lt;br /&gt;After renaming the file I was greated with this lovely error:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Error updating JScript IntelliSense: D:\Source\...\JS\jquery\jquery-1.3.2-vsdoc.js: 'div.childNodes' is null or not an object @ 1487:1&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;My understanding is that the code inside the methods doesn't really matter (Assuming it's not changing the object definitions of course). Since this code will never be ran, I simply removed line 1488 which looks like:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;elem = jQuery.makeArray(div.childNodes);&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And now we have intellisense working with jquery 1.3.2&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_x1o4p4pyxUQ/SibXUN94wjI/AAAAAAAAAAk/5evDR-q8540/s1600-h/vsintellisenseworking.png"&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 320px; DISPLAY: block; HEIGHT: 91px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5343194750268260914" border="0" alt="" src="http://1.bp.blogspot.com/_x1o4p4pyxUQ/SibXUN94wjI/AAAAAAAAAAk/5evDR-q8540/s320/vsintellisenseworking.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;span style='font-weight:bold'&gt;Edit&lt;/span&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;I've noticed a lot of traffic recently on this post, if this post has helped resolve your issue (or not helped) leave a comment let others know.&lt;br /&gt;&lt;br /&gt;Thank you and good luck&lt;br /&gt;&lt;br /&gt;-jb&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-4813371897287923802?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/4813371897287923802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=4813371897287923802' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/4813371897287923802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/4813371897287923802'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/06/jquery-132-intellisense-in-visual.html' title='Jquery 1.3.2 &amp; Intellisense in Visual Studio 2008'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_x1o4p4pyxUQ/SibXUN94wjI/AAAAAAAAAAk/5evDR-q8540/s72-c/vsintellisenseworking.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-7200013906209229180</id><published>2009-05-21T12:44:00.004-04:00</published><updated>2009-09-02T04:28:38.251-04:00</updated><title type='text'>One more VSS bites the dust</title><content type='html'>I am happy to announce, that I have just my finished my second VSS to TFS migration, and I hope and pray that I will never be forced to open up VSS again. Yahooo!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-7200013906209229180?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/7200013906209229180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=7200013906209229180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/7200013906209229180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/7200013906209229180'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/05/one-more-vss-bites-dust.html' title='One more VSS bites the dust'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-5763031809730082585</id><published>2009-05-19T13:26:00.005-04:00</published><updated>2009-05-19T13:36:47.571-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='ComponentArt'/><title type='text'>Rendering ComponentArt's Splitter in Firefox</title><content type='html'>I've been working a little bit to add support for FireFox in my application which has only supported IE6 and better. I am trying to be proactive knowing one day my boss will ask for this, and it is actually helping to cleanup the markup we have quite a bit. &lt;br /&gt;&lt;br /&gt;Along this journey, I noticed that we have a splitter bar, which has a tree view in one pane and a tree view in a second pane. It is a two pane vertical split. In IE6,7 and 8 (even in standards mode), the pane rendered correctly. When viewed in Firefox the first pane was shown; however, the second pane wasn't being rendered. It looked like the splitter container width was being set to the width of the first pane, which caused that pane to take up the entire container. &lt;br /&gt;&lt;br /&gt;After working with Component Art's support team, it was noticed that when you resize the window, the pane would then render correctly. With their help, we found the following to force the splitters to render correctly in firefox.&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;function&lt;/span&gt; splitter_load() {&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (jQuery.browser.mozilla) {&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; splitter.element.style.width = &lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; $(&lt;span style="color: #a31515;"&gt;"#divBidSummary"&lt;/span&gt;).width() + &lt;span style="color: #a31515;"&gt;"px"&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; splitter.adjustSize(&lt;span style="color: blue;"&gt;true&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;myContainer is a div which I have set to a width of 99% of it's parent. This allows the splitter to grow and shrink as the page is resized. This sample uses &lt;a href="http://jquery.com"&gt;jquery&lt;/a&gt;, which is an excellant javascript library.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; Thanks goes out to Hwan to helping to track down and develop a work around for this solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-5763031809730082585?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/5763031809730082585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=5763031809730082585' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5763031809730082585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5763031809730082585'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/05/rendering-componentarts-splitter-in.html' title='Rendering ComponentArt&apos;s Splitter in Firefox'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-3300148520175961660</id><published>2009-05-19T12:12:00.006-04:00</published><updated>2009-05-19T12:38:43.438-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='ComponentArt'/><title type='text'>Automatic text selection with Compenant Art's Tree View</title><content type='html'>Over the last year I have been using &lt;a href="http://www.componentart.com/"&gt;Component Art's&lt;/a&gt; Web UI suite. I have a love hate relationship with their controls. I love how they are quick and easy to get some advanced UI functionality into your site. I hate their documentation and that some features which I would consider basic seem to be missing. I also want to take a moment and say they have a great tech support team, who has helped me quite a bit over the last year. But overall I would recommend the controls.&lt;br /&gt;&lt;br /&gt;In a recent project, I had a tree view, which the user could create their own nested heirarchial tree, they could move the nodes around, and it worked very simillar to the experience you get with Windows Explorer. One minor feature which was missing, that I had wanted (and some of my test user's also asked for), was that when you go to edit the name of the node, select the text for them. &lt;br /&gt;&lt;br /&gt;This is a basic UI paradigm that if I go to edit something it automaticly selects itself. When you look at the TreeView control you will see there is no event that indicates that a node is being edited; however, if you don't mind mucking around with a thrid party object (This is something that should not be done lightly CA makes no promises that this will work in future versions) there is a way to do this.&lt;br /&gt;&lt;br /&gt;If you examine the TreeViewNode object you will find a method called Edit which is called when a node is supposed to go into Edit mode. By overridding this method we can provide our own implementation for method. The following code copies the Edit function into a new function EditOriginal. It then creates a new Edit function which calls the original function. The new function then uses &lt;a href="http://jquery.com/"&gt;Jquery&lt;/a&gt; to select an input which is a child of a TreeView class. If your not using &lt;a href="http://jquery.com/"&gt;Jquery&lt;/a&gt; or if your page structure is different you might need to modify that code to find the input element, and then select it.&lt;br /&gt; &lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ComponentArt_TreeViewNode.prototype.EditOriginal = ComponentArt_TreeViewNode.prototype.Edit;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ComponentArt_TreeViewNode.prototype.Edit = &lt;span style="color: blue;"&gt;function&lt;/span&gt;() {&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;this&lt;/span&gt;.EditOriginal();&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; $(&lt;span style="color: #a31515;"&gt;'.TreeView input'&lt;/span&gt;).select();&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;There is an EditNodeCSS property which I was unable to get a selector working with it. If anyone does get a selection working off that let me know. I'd love to know where in the dom its used and when I try and look at it with my tools the node leaves edit mode.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; I want to thank Stephen Hatcher of Component Art's Tech Support team for his assistance in coming up with this solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-3300148520175961660?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/3300148520175961660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=3300148520175961660' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3300148520175961660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3300148520175961660'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/05/automatic-text-selection-with-compenant.html' title='Automatic text selection with Compenant Art&apos;s Tree View'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-2616610547564661776</id><published>2009-05-15T11:34:00.004-04:00</published><updated>2009-05-15T11:48:18.197-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='css'/><title type='text'>Centering Box Elements in HTML with CSS</title><content type='html'>Most of my carreer I have been a "backend" guy, working on the database, and building services for consumption by other systems. Over the last couple of years I have had the pleasure of becoming a "frontend" guy, working on various web sites.&lt;br /&gt;&lt;br /&gt;So far the site I have been working on only targets IE, As such there hasn't been a strong motiviation to add support for Firefox; however, with IE8 being much more standards compliant, I have a personal desire to get the site to a point where I can turn off IE7 Compatability Mode. &lt;br /&gt;&lt;br /&gt;Today I was a little stumped when I was working on markup simillar to the following:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;div&lt;/span&gt; &lt;span style="color: red;"&gt;style&lt;/span&gt;&lt;span style="color: blue;"&gt;="&lt;/span&gt;&lt;span style="color: red;"&gt;text-align&lt;/span&gt;: &lt;span style="color: blue;"&gt;center"&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;table&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;tr&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;td&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; I am Centered&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;td&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;tr&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;table&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;div&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;In IE8 with Compatability mode this renders as I expect. The table is centered within the div; however, in Firefox and IE8 standard mode the table is left aligned. &lt;br /&gt;&lt;br /&gt;I've always questioned why am I using text-align to align elements, but it always worked so I just shrugged and moved on. Turns out IE wasn't honoring that text-align should only align text. It was using to align all elements. The proper way to do this is:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;div&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;table&lt;/span&gt; &lt;span style="color: red;"&gt;style&lt;/span&gt;&lt;span style="color: blue;"&gt;="&lt;/span&gt;&lt;span style="color: red;"&gt;margin-left&lt;/span&gt;:&lt;span style="color: blue;"&gt;auto&lt;/span&gt;;&lt;span style="color: red;"&gt;margin-right&lt;/span&gt;:&lt;span style="color: blue;"&gt;auto"&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;tr&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;td&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; I am Centered&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;td&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;tr&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;table&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;div&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is so much better. I hated having to use text-align center, and then go through and set all the text up so it would align back left. I have tested this in Firefox 3.0.7 and IE8 (IE7 and Standards Mode). It feels to good finally learn the right way to do something.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-2616610547564661776?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/2616610547564661776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=2616610547564661776' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/2616610547564661776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/2616610547564661776'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/05/centering-box-elements-in-html-with-css.html' title='Centering Box Elements in HTML with CSS'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-586182704410437627</id><published>2009-05-05T15:15:00.005-04:00</published><updated>2009-05-08T10:49:12.059-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Dynamic Expression</title><content type='html'>Scott Gu has a good &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx"&gt;article&lt;/a&gt; about a great sample component called Dynamic Linq. This is a very powerful addition to your linq toolkit which lets you create expressions based on strings. So imagine that you want to add sorting to a grid which is bound to a List&lt;BusinessObject&gt;. One way would be to have a switch statement for each options (Yes you can throw up I'll wait).&lt;br /&gt;&lt;br /&gt;Another way would be to use the dynamic query library. I've always wondered how difficult it would be to create an Expression dynamically. This would be a nice addition to my Audit Logger allowing for the configuration of an audit category to exist outside of the code.&lt;br /&gt;&lt;br /&gt;Much of this code came from &lt;a href="http://stackoverflow.com/questions/802789/extension-method-to-sort-a-list-within-a-parent-object/802845#802845"&gt;this stackoverflow.com article&lt;/a&gt;. I simply went and added the glue:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; Sort&amp;lt;T&amp;gt;(&lt;span style="color: blue;"&gt;this&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; source,&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;string&lt;/span&gt; sortExpression, &lt;span style="color: blue;"&gt;bool&lt;/span&gt; desc)&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; param = &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt;.Parameter(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(T), &lt;span style="color: blue;"&gt;string&lt;/span&gt;.Empty);&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; fields = sortExpression.Split(&lt;span style="color: #a31515;"&gt;'.'&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt; property = &lt;span style="color: blue;"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt; parentParam = param;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue;"&gt;var&lt;/span&gt; field &lt;span style="color: blue;"&gt;in&lt;/span&gt; fields)&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; property = &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt;.Property(parentParam, field);&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; parentParam = property;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; sortLambda = &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt;.Lambda&amp;lt;&lt;span style="color: #2b91af;"&gt;Func&lt;/span&gt;&amp;lt;T, &lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;gt;&amp;gt;(&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Expression&lt;/span&gt;.Convert(property, &lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: blue;"&gt;object&lt;/span&gt;)),&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; param);&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (desc)&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; source.AsQueryable&amp;lt;T&amp;gt;().OrderByDescending&amp;lt;T, &lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;gt;(sortLambda);&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; source.AsQueryable&amp;lt;T&amp;gt;().OrderBy&amp;lt;T, &lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;gt;(sortLambda);&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Basically this will give you an expression which returns the value of a property. It will support property / field invocation so myObject.MyField.MyProperty. It works by creating an expression which represents the type of parameter being pased in to the lambda.&lt;br /&gt;&lt;br /&gt;Then it builds an expression tree by chaining new expressions together for each token myObject, myField etc. Finally it creates a lambda which can be executed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-586182704410437627?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/586182704410437627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=586182704410437627' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/586182704410437627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/586182704410437627'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/05/dynamic-expression.html' title='Dynamic Expression'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-6152444682046097653</id><published>2009-04-29T14:19:00.004-04:00</published><updated>2009-04-29T14:31:08.082-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>MVC For IDE's</title><content type='html'>Recently I had the pleasure of helping out a former employer of mine resolve a couple minor issues that have come up since my departure. During this time I had a revelation about how we treat our source code today, and how we should treat it tomorrow. &lt;br /&gt;&lt;br /&gt;When I worked for this company I became the sole developer, and was able to define my own coding standards. Overtime all of the source files were updated, as I made changes to them, and was able to use Reformat Document tool in Visual Studio. &lt;br /&gt;&lt;br /&gt;Since I have left, a new developer has taken ownership of all the projects I was working on. Said developer prefers a different style to their code. For example. I prefer all braces to start on a new line where as he prefers all opening braces to exist on the parent line.&lt;br /&gt;&lt;br /&gt;What does this have to do with how we treat source code? Well imagine this scenario. I open up a large class file, and remove a single using statement from the top of the file. Upon saving the file, visual studio applies my formatting rules which I defined. This results in my one line change to cascade into hundreds of changes.&lt;br /&gt;&lt;br /&gt;The question I pose then is why do our tools treat non-significant characters such as extra white space as significant when comparing two versions of the code? Shouldn't our development tools store the source code in as compact a format as possible and allow us to define our own personal views of the source code? Two developers on the same team should be able to read the same source code formatted how they like to see it.&lt;br /&gt;&lt;br /&gt;Perhaps Visual Studio should be written as a MVC, and allow us to define our own views seperate from the source code. &lt;br /&gt;&lt;br /&gt;Writting this reminded me of when I worked on VB6 applications and one developer would check out a file and the casing of all the variables would change. What a nightmare. Again the source code should be treated as data rendered into a view by the IDE.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-6152444682046097653?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/6152444682046097653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=6152444682046097653' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6152444682046097653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6152444682046097653'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/04/mvc-for-ides.html' title='MVC For IDE&apos;s'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-3575607597216570858</id><published>2009-04-28T18:08:00.002-04:00</published><updated>2009-04-28T18:19:34.759-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net MVC'/><title type='text'>Rendering to Xml with ASP.Net MVC</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Warning: This is my first post using Windows Live Writer so if things don’t come out right I apologize. &lt;/p&gt;  &lt;p&gt;I have been working lately on using the ASP.Net MVC platform as a rest based endpoint. My current consumer is looking for xml documents of our model; however, in the future I’d love to move our web site over as well. I have been playing around with a couple of different ways to render xml content from a view. &lt;/p&gt;  &lt;p&gt;I have seen some approaches on the web which use an automatic serialization mechanism to convert your model into xml or json. I feel that this should not be done automatically but you should be able to customize the rendering however way you need. This has led me to try out three different options to date.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Option 1 Serializing a DTO&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The first approach I tried was to take my DTO and get into Xml the quickest easiest way possible. The XmlSerializer. This broke down a little bit when I discovered I actually needed two DTO’s. This method I used a helper method in a code behind file. So my view looks like:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; Inherits=&amp;quot;MyViewToXml&amp;quot; CodeBehind=&amp;quot;MyViewToXml.aspx.cs&amp;quot;  %&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.RenderToXml(); &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now if we look at RenderToXml we can see the magic here:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;  &lt;pre class="csharpcode"&gt;Response.ContentType = &lt;span class="str"&gt;&amp;quot;text/xml&amp;quot;&lt;/span&gt;;&lt;br /&gt;Response.Write(&lt;span class="str"&gt;&amp;quot;&amp;lt;MyRoot&amp;gt;&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;var dcs = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(List&amp;lt;DTO1&amp;gt;));&lt;br /&gt;dcs.WriteObject(Response.OutputStream, &lt;span class="kwrd"&gt;this&lt;/span&gt;.Model);&lt;br /&gt;&lt;br /&gt;var dcs2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IList&amp;lt;DTO2&amp;gt;));&lt;br /&gt;IList&amp;lt;DTO2&amp;gt; bfs = (IList&amp;lt;DTO2r&amp;gt;)&lt;span class="kwrd"&gt;this&lt;/span&gt;.ViewData[&lt;span class="str"&gt;&amp;quot;DTO2&amp;quot;&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;dcs2.WriteObject(Response.OutputStream, bfs);&lt;br /&gt;&lt;br /&gt;Response.Write(&lt;span class="str"&gt;&amp;quot;&amp;lt;/MyRoot&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I like this approach in that it was quick easy, and gave me full control, but it doesn’t sit well with me. It feels like I am grinding against the purpose of having a view. So let’s look at option 2.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Option 2 Embracing MVC View&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;My next shot was to serialize a much more complex object. In my actual case I don’t have a DTO defined, and I need to have even more control over the Xml being generated. Serialization by the framework won’t cut it, and I wasn’t go back 10 years to the days of having build xml via strings or even via a DOM. So what does that leave me with?&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Order&lt;/span&gt; &lt;span class="attr"&gt;Id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.Id%&amp;gt;&amp;quot;&lt;/span&gt;  &lt;span class="attr"&gt;Number&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.Number%&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;     &lt;br /&gt; &lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&gt;&lt;span class="html"&gt;Customer&lt;/span&gt; &lt;span class="attr"&gt;Company&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.CompanyName %&amp;gt;&amp;quot;&amp;gt;&lt;/span&gt; &lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Address&lt;/span&gt; &lt;span class="attr"&gt;Line1&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.Address.Line%&amp;gt;&amp;quot;&lt;/span&gt; &lt;br /&gt;            &lt;span class="attr"&gt;City&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.Address.City %&amp;gt;&amp;quot;&lt;br /&gt;&lt;/span&gt;&lt;span class="attr"&gt;            State&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.Address.State %&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Customer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ShipTo&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.Location.Name %&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;this&lt;/span&gt;.Model.ShipTo.Equals(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Model.Contact.Address))&lt;br /&gt;      {  &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Address&lt;/span&gt; &lt;span class="attr"&gt;City&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.ShipTo.City %&amp;gt;&amp;quot;&lt;/span&gt; &lt;br /&gt;            &lt;span class="attr"&gt;State&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.ShipTo.State %&amp;gt;&amp;quot; &lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ShipTo&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Items&lt;/span&gt; &lt;span class="attr"&gt;GrandTotal&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.CalculateGrandTotal()%&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;&lt;br /&gt;           IsOverride&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=this.Model.IsGrandTotalOverridden %&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt;(var item &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.Model.Items) {&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Item&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=item.Name%&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Total&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=item.Total%&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Items&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Order&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here we are embracing the view and generating our xml just as if we were rendering an Xhtml view of the domain. This is neat; however, it is a little verbose so I started to question what else is out there.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Option 3 Finding Alternate View Engines&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Asp.Net MVC is very extensible. If you don’t like the view engine go find a new one or write your own. I ran across a port of HAML called &lt;a href="http://andrewpeters.net/2007/12/19/introducing-nhaml-an-aspnet-mvc-view-engine/"&gt;NHAML&lt;/a&gt;. This can simplify the syntax to look at; however, NHAML’s tooling is not there. If you want intellisense or color highlighting, its just not there.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Further more it treats white space as significant characters. For example to nest elements you would need to do:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;  %Order &lt;br /&gt;    &amp;#160; %Customer &lt;br /&gt;    &amp;#160;&amp;#160;&amp;#160; %Address &lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Child elements are indented by two spaces. While this frees you from worrying about closing all your tags, its a little counterintuitive. There are other view engines out there, which I am looking forward to running through their paces.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-3575607597216570858?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/3575607597216570858/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=3575607597216570858' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3575607597216570858'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3575607597216570858'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/04/rendering-to-xml-with-aspnet-mvc.html' title='Rendering to Xml with ASP.Net MVC'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-3016425067081053054</id><published>2009-04-02T12:14:00.006-04:00</published><updated>2009-04-02T12:35:50.861-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='SSRS'/><title type='text'>Setting up SSRS on server with multiple sites</title><content type='html'>I had to set up SSRS on a server today, which has about six or seven different sites. I went through and configured SSRS, bound the virtual directories to a free IP address, fired up the browser and kaboom!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_x1o4p4pyxUQ/SdTlwOVTQ2I/AAAAAAAAAAc/Scwsrg7fCnw/s1600-h/ssrs400Error.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5320129676475319138" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 141px; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_x1o4p4pyxUQ/SdTlwOVTQ2I/AAAAAAAAAAc/Scwsrg7fCnw/s320/ssrs400Error.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Firing up google was very frustrating as all the solutions I was finding told me to check permissions. The issue here is most likely due to SSRS defaulting to using &lt;em&gt;http://localhost&lt;/em&gt; to access the web services. (If anyone from Microsoft or knows whose responsible for this piece of code it'd be great to give a little bit more detail). How do you tell SSRS to use a different server?&lt;br /&gt;&lt;br /&gt;There is a config file in &lt;em&gt;%SQL Install Folder%\MSSQL.*\Reporting Services\ReportManager\RSWebApplication.config.&lt;/em&gt;. In side this file you will see some xml which looks like&lt;br /&gt;&lt;br /&gt;&amp;lt;ui&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;reportserverurl&amp;gt;&amp;lt;/reportserverurl&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;reportservervirtualdirectory&amp;gt;ReportServer&amp;lt;/reportservervirtualdirectory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;reportbuildertrustlevel&amp;gt;FullTrust&amp;lt;/reportbuildertrustlevel&amp;gt;&lt;br /&gt;&amp;lt;/ui&amp;gt;&lt;br /&gt;&lt;br /&gt;Perfect right so I enter in the URL for my site, fire up the report manager and....kaboom! This time the site doesn't even load and we get the following error from our log files:&lt;br /&gt;&lt;br /&gt;w3wp!diagnostic!6!4/2/2009-12:03:16:: Error loading configuration file: The configuration file contains an element that is not valid. The ReportServerUrl element is not a configuration file&lt;br /&gt;&lt;br /&gt;This is a horrible error message and doesn't really indicate what the issue. Turns out that you can have either ReportServerUrl or ReportServerVirtualDirectory. Enter the fully qualified URL for ReportServerUrl and remove the ReportServerVirtualDirectory node. Now we fire up the ReportManager in your favorite web browser...and...it works!&lt;br /&gt;&lt;br /&gt;I could have saved many many hours and advil, had the developers done proper error handling. Ahh well hopefully you find this article before you've wasted to many hours.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-3016425067081053054?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/3016425067081053054/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=3016425067081053054' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3016425067081053054'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/3016425067081053054'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/04/setting-up-ssrs-on-server-with-multiple.html' title='Setting up SSRS on server with multiple sites'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_x1o4p4pyxUQ/SdTlwOVTQ2I/AAAAAAAAAAc/Scwsrg7fCnw/s72-c/ssrs400Error.png' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-5549312597208108052</id><published>2009-03-19T14:43:00.003-04:00</published><updated>2009-03-19T14:54:08.281-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='nHibernate'/><title type='text'>nHibernates poor validation of mapping files</title><content type='html'>One thing that I have come to notice as I've been using nHibernate is that it does a very poor job at validating that mapping files make sense. One could argue that I shouldn't write poor shoddy mapping files in the first place. I would beg instead to tell me when I've written a poor shoddy mapping file.&lt;br /&gt;&lt;br /&gt;Here's the scenario I just faced. I was working with an Entity which has a One to One relationship with some legacy code which doesn't use nHibernate. When I first mapped this I had an identity column on the table. After thinking about it, I want to enforce that we have a one to one so I then modified my schema and mapping file to use the FK field as its identity. I went from this:&lt;br /&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red163\green21\blue21;\red225\green213\blue215;\red0\green0\blue255;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1\cb2\highlight2 class\cf3  \cf4 name\cf3 =\cf0 "\cf3 MyOptions\cf0 "\cf3   \cf4 lazy\cf3 =\cf0 "\cf3 false\cf0 "\cf3 &amp;gt;\par ??\tab &amp;lt;\cf1 id\cf3  \cf4 column\cf3 =\cf0 "\cf3 id\cf0 "\cf3  \cf4 name\cf3 =\cf0 "\cf3 Id\cf0 "\cf3   &amp;gt;\par ??\tab \tab &amp;lt;\cf1 generator\cf3  \cf4 class\cf3 =\cf0 "\cf3 native\cf0 "\cf3 /&amp;gt;\par ??\tab &amp;lt;/\cf1 id\cf3 &amp;gt;\par ??\tab &amp;lt;\cf1 property\cf3  \cf4 name\cf3 =\cf0 "\cf3 FkId\cf0 "\cf3 /&amp;gt;\par ??&amp;lt;/\cf1 class\cf3 &amp;gt;}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: #a31515;"&gt;class&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;MyOptions&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color: red;"&gt;lazy&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;false&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;id&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;column&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;id&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Id&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;generator&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;class&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;native&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;id&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;property&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;FkId&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;class&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To this:&lt;br /&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red225\green213\blue215;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1\cb2\highlight2 &amp;lt;\cf3 class\cf1  \cf4 name\cf1 =\cf0 "\cf1 MyOptions\cf0 "\cf1   \cf4 lazy\cf1 =\cf0 "\cf1 false\cf0 "\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 id\cf1  \cf4 column\cf1 =\cf0 "\cf1 FkId\cf0 "\cf1  \cf4 name\cf1 =\cf0 "\cf1 FkId\cf0 "\cf1  \cf4 unsaved-value\cf1 =\cf0 "\cf1 any\cf0 "\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 generator\cf1  \cf4 class\cf1 =\cf0 "\cf1 assigned\cf0 "\cf1 /&amp;gt;\par ??\tab &amp;lt;/\cf3 id\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 property\cf1  \cf4 name\cf1 =\cf0 "\cf1 FkId\cf0 "\cf1 /&amp;gt;\par ??&amp;lt;/\cf3 class\cf1 &amp;gt;}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;class&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;MyOptions&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color: red;"&gt;lazy&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;false&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;id&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;column&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;FkId&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;FkId&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;unsaved-value&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;any&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;generator&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;class&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;assigned&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;id&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;property&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;FkId&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;class&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I fire this up, and we have no initialization issues, I am also to read data in without an issue. But when I go to save the data, I get an IndexOutOfRange exception when nHibernate tries to access a parameter. &lt;br /&gt;&lt;br /&gt;Do you see the issue? I left my property for FkId in the mapping file. I needed to remove it since it is now the Id. Which caused parts of nHibernate to break. Interestingly enough when I look at the insert statement it only had the FkId field being inserted into once. So part of nHibernate handles my shoddy mapping file but other parts do not. &lt;br /&gt;&lt;br /&gt;Anyways nHibernate is still an awsome tool, and hats off to the people who devote their time without pay to such a great tool.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-5549312597208108052?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/5549312597208108052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=5549312597208108052' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5549312597208108052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5549312597208108052'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/03/nhibernates-poor-validation-of-mapping.html' title='nHibernates poor validation of mapping files'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-6525233933680658158</id><published>2009-03-19T09:54:00.004-04:00</published><updated>2009-03-19T11:43:06.838-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Dynamically call a Generic method using Reflection</title><content type='html'>While working on a request to make the &lt;a href="http://jberke.blogspot.com/2008/09/logging-to-database-with-enterprise.html"&gt;Database Logging add-on&lt;/a&gt; I discussed &lt;a href="http://jberke.blogspot.com/search/label/EntLib"&gt;previously&lt;/a&gt;, I came accross an interesting problem.&lt;br /&gt;&lt;br /&gt;I wanted to be able to define the name of the ExpressionGroup, stored procedure and connection to use when logging to the database in a config file. I figure this was the first step in enabling configuration to the system. In order to do this I needed to create an instance of Expression&amp;lt;T&amp;gt;. &lt;br /&gt;&lt;br /&gt;The expression cache already has a CreateGroup&amp;lt;T&amp;gt;() method which I wanted to use. So how can I call this method if I don't know the type of T until runtime? Its actually very easy.&lt;br /&gt;&lt;br /&gt;Essentially you want to get a reference to the Method via Reflection. There are lots of ways to do this. Once you have a MethodInfo class, you can call MakeGenericMethod which takes a parameter array of type objects. It will use these type objects to subsitute in place for the Generic type T.&lt;br /&gt;&lt;br /&gt;At this point you can call the method just like any other method via reflection, using the Invoke() method on MethodInfo. The code looks like this:&lt;br /&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red225\green213\blue215;\red0\green0\blue0;\red163\green21\blue21;\red43\green145\blue175;}??\fs20 \cf1\cb2\highlight2 var\cf0  meth = \cf1 this\cf0 .GetType().GetMethod(\cf4 "CreateGroup"\cf0 );\par ??\cf1 var\cf0  genericMeth=meth.MakeGenericMethod(getType(grpConfig.AuditLogEntryType));\par ??\cf5 IAuditLoggerExpressionGroup\cf0  expGroup = (\cf5 IAuditLoggerExpressionGroup\cf0 )genericMeth.Invoke(\cf1 this\cf0 , \cf1 new\cf0  \cf1 object\cf0 [] \{ grpConfig.Name, grpConfig.ConnectionName, grpConfig.Procedure \});\par ??\cf1 this\cf0 .Add(expGroup);}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt; meth = &lt;span style="color: blue;"&gt;this&lt;/span&gt;.GetType().GetMethod(&lt;span style="color: #a31515;"&gt;"CreateGroup"&lt;/span&gt;);&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt; genericMeth=meth.MakeGenericMethod(getType(grpConfig.AuditLogEntryType));&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: #2b91af;"&gt;IAuditLoggerExpressionGroup&lt;/span&gt; expGroup = (&lt;span style="color: #2b91af;"&gt;IAuditLoggerExpressionGroup&lt;/span&gt;)genericMeth.Invoke(&lt;span style="color: blue;"&gt;this&lt;/span&gt;, &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: blue;"&gt;object&lt;/span&gt;[] { grpConfig.Name, grpConfig.ConnectionName, grpConfig.Procedure });&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.Add(expGroup);&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's all there is to it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-6525233933680658158?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/6525233933680658158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=6525233933680658158' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6525233933680658158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6525233933680658158'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/03/dynamically-call-generic-method-using.html' title='Dynamically call a Generic method using Reflection'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-6597482426236192010</id><published>2009-03-11T12:16:00.005-04:00</published><updated>2009-04-02T12:36:29.476-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Extension Methods &amp; Null Objects</title><content type='html'>I ran into an issue that I had learned about a while ago but the code that I was working on predated this. I find it interesting enough to share. I love the various predicate / action methods on List&amp;lt;T&amp;gt; that allows you to interact with a list by passing in a delegate. &lt;br /&gt;&lt;br /&gt;I've always been a little dissapointed that these methods aren't part of the IList&amp;lt;T&amp;gt; interface; however, with Extension methods we can rectify this. I defined a new method in a static class as:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; T Find&amp;lt;T&amp;gt;(&lt;span style="color: blue;"&gt;this&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IList&lt;/span&gt;&amp;lt;T&amp;gt; col, &lt;span style="color: #2b91af;"&gt;Predicate&lt;/span&gt;&amp;lt;T&amp;gt; match)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (match == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"match"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;for&lt;/span&gt; (&lt;span style="color: blue;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; col.Count; i++)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (match(col[i]))&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; col[i];&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;default&lt;/span&gt;(T);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This has been working fine for almost a year now, until today when I got a null Reference exception on the &lt;em&gt;for loop&lt;/em&gt;. The interesting thing with Extension methods is they are nothing more then a static method that the compiler does some magic with. &lt;br /&gt;&lt;br /&gt;To prove this go ahead and create a simple console application. Add an extension method on your favorite type (I choose a string), and call this from your main method. Here's what I used:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Extensions&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; ToMe(&lt;span style="color: blue;"&gt;this&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; value)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (value == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515;"&gt;"Null value"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue;"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;string&lt;/span&gt; s = &lt;span style="color: blue;"&gt;null&lt;/span&gt;;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; s.ToMe();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Console&lt;/span&gt;.ReadLine();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;After you compile this go ahead and fire up reflector or Ildasm and have a look at the IL. In my case I had the following instruction:&lt;br /&gt;&lt;b&gt;call void ConsoleApplication4.Extensions::ToMe(string)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Since all we are doing is calling a static method and passing in a reference to the variable which the extension method was called off of, it becomes perfectly legal to call extension methods on a null reference.&lt;br /&gt;&lt;br /&gt;Now in my opinion this is wrong, and a side effect of the implementation, and we should not rely upon this behavior. The correct code should look like:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; T Find&amp;lt;T&amp;gt;(&lt;span style="color: blue;"&gt;this&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IList&lt;/span&gt;&amp;lt;T&amp;gt; col, &lt;span style="color: #2b91af;"&gt;Predicate&lt;/span&gt;&amp;lt;T&amp;gt; match)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (match == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"match"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (col == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NullReferenceException&lt;/span&gt;();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;for&lt;/span&gt; (&lt;span style="color: blue;"&gt;int&lt;/span&gt; i = 0; i &amp;lt; col.Count; i++)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (match(col[i]))&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; col[i];&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;default&lt;/span&gt;(T);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-6597482426236192010?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/6597482426236192010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=6597482426236192010' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6597482426236192010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/6597482426236192010'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/03/extension-methods-null-objects.html' title='Extension Methods &amp; Null Objects'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-5399435611246799232</id><published>2009-03-09T16:53:00.004-04:00</published><updated>2009-04-02T12:36:55.561-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WTF'/><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><title type='text'>Benefits of obfuscating and pointless licensing systems</title><content type='html'>Recently I was faced with a difficult problem. A component that a contractor choose for a site which I now maintain, is licensed per domain name. The site is for a relativley young company which hadn't choosen how it was going to brand the software they were selling. &lt;br /&gt;&lt;br /&gt;After they had choosen the domain they wanted, we switched the site over and the component as we knew was going to break. We had emailed the control's manufacturer three times over a three month period, and they never replied to us. So now I was stuck with the following choices. Either we buy another license through their channel, replace the control, or find a plan c.&lt;br /&gt;&lt;br /&gt;Considering they hadn't responded to any of my emails, I was reluctant to send them any more money. The control was used extensivley in a site that isn't worth the time to replace so that leaves us with plan c. &lt;br /&gt;&lt;br /&gt;I have to state that plan c is a temporary fix until they respond to our emails. So I started digging around in the compiled assemblies wondering if there was a way to get around this licensing issue (again as a temporary fix). &lt;br /&gt;&lt;br /&gt;What I saw shocked me. First the assembly wasn't obfuscated. Had it been obfuscated, I probally would have given up, as I only wanted to spend 20 minutes on this max. The second thing was that licensing scheme basically makes a call to an external assembly which returns a decrypted string that the caller then used to match against the URL's, or it would match against the host name if the string was properly formated. &lt;br /&gt;&lt;br /&gt;Well this was easy to fix. All I had to do was create a new assembly which matched their signature, and return a very simple string. This was the only thing this assembly did. &lt;br /&gt;&lt;br /&gt;This is where obfuscating becomes important, it is not fool proof but again nothing is foolproof, if the computer can understand someone somewhere can understand but you want to raise the bar high enough to make it so that it is not worth ones time to break through. &lt;br /&gt;&lt;br /&gt;I'm also confused why they shipped this assembly seperate had it been compiled with the rest of their stuff it would have been riskier for me to mess around with it. Lesson learned here is either protect your code a little bit, or at least be competent enough to respond to customers emails.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-5399435611246799232?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/5399435611246799232/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=5399435611246799232' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5399435611246799232'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5399435611246799232'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/03/benefits-of-obfuscating-and-pointless.html' title='Benefits of obfuscating and pointless licensing systems'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-8303613437608848622</id><published>2009-03-01T11:54:00.004-05:00</published><updated>2009-03-01T13:00:09.024-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net MVC'/><title type='text'>ASP.net MVC Model Binder</title><content type='html'>Model Binders is a powerful extension point to the ASP.NET MVC. It allows you to define your own class which is responsible for creating parameters for your controller actions. &lt;a href="http://www.hanselman.com/blog/IPrincipalUserModelBinderInASPNETMVCForEasierTesting.aspx"&gt;Scott Hansleman had a good example &lt;/a&gt;showing how to decouple a controller from HttpContext's user property.&lt;br /&gt;&lt;br /&gt;Recently I've started a new Proof of Concept site which is based upon &lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;REST&lt;/a&gt;. My goal was to build a single web site which would expose its resources as addressable items. That is the URL defines the resource. This site should also be able to serve multiple clients which want different representations of the same resource.&lt;br /&gt;&lt;br /&gt;For example assume we have an Automobile Parts catalog. We might have the browser point to &lt;a href="http://mypartscatalog.com/Ford/OilFilters/"&gt;http://myPartsCatalog.com/Ford/OilFilters/&lt;/a&gt; which would render an HTML page of all the ford oil filters. Now let us say we want to implement an AJAX callback on the page so as a user mouse overs a specific part, the site might send a request to &lt;a href="http://mypartscatalog.com/Ford/OilFilters/fl1a"&gt;http://myPartsCatalog.com/Ford/OilFilters/fl1a&lt;/a&gt;, with the intention of gathering additional data about the part to display to the user. For this request we don't want to get an HTML representation of the part, we want the part rendered as JSON or XML, which will let us programatically access the part information.&lt;br /&gt;&lt;br /&gt;I have grown tired of having to support multiple sites / pages one that renders the HTML and another that provides an API and exposes the data. The natural seperation of concerns that the MVC model gives us makes this an ideal platform to build a single web site which can serve HTML, XML, JSON or any other content we could imagine (for example what about a PDF version of the HTML page for offline usages).&lt;br /&gt;&lt;br /&gt;To do this imagine we have the following controller defined:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;PartController&lt;/span&gt; : &lt;span style="color:#2b91af;"&gt;Controller&lt;/span&gt;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;     public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ActionResult&lt;/span&gt; List(&lt;span style="color:blue;"&gt;string&lt;/span&gt; oem)&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;    public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ActionResult&lt;/span&gt; Detail(&lt;span style="color:blue;"&gt;string&lt;/span&gt; oem, &lt;span style="color:blue;"&gt;string&lt;/span&gt; partnumber)&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We need a way to determine how the client wants the data to be returned. We could put that in the URL; however, that doesn't feel very restful. A key idea of a REST implementation is leveraging the capabilities in the HTTP protocol to define the resource your requesting. One of the Http Header's is &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html"&gt;Accept&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;The Accept header allows us to define the content type that the client is requesting. So we could indicate in our request that we want text/json or text/xml. We could then put the following code in our controller:&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ActionResult&lt;/span&gt; List(&lt;span style="color: blue;"&gt;string&lt;/span&gt; oem)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//Get the Model for OEM.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;switch&lt;/span&gt; (HttpContext.Request.AcceptTypes[0])&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;case&lt;/span&gt; &lt;span style="color: #a31515;"&gt;"*/*"&lt;/span&gt;:&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;case&lt;/span&gt; &lt;span style="color: #a31515;"&gt;"text/html"&lt;/span&gt;:&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515;"&gt;"PartList.aspx"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;case&lt;/span&gt; &lt;span style="color: #a31515;"&gt;"text/json"&lt;/span&gt;:&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515;"&gt;"PartList.json.aspx"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;b&gt;Warning:&lt;/b&gt; I am not finished investgating how ASP.Net handles the Accept header and my switch statement might not work; however, this is an example to highlight the flexibility of ASP.Net MVC.&lt;br /&gt;&lt;br /&gt;So this works great; except that we want to unit test our code to ensure we are returning the right view for each request; however our controller is bound HttpContext which can be difficult to unit test. So the question is how do we decouple our controller from HttpContext? IModelBinder's are the answer.&lt;br /&gt;&lt;br /&gt;We can define a ModelBinder by implementing the IModelBinder interface. The interface requires a single method that takes a couple parameters which provide context about the request, and returns an object.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ContentTypeModelBinder&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IModelBinder&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; IModelBinder Members&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;object&lt;/span&gt; BindModel(&lt;span style="color: #2b91af;"&gt;ControllerContext&lt;/span&gt; controllerContext, &lt;span style="color: #2b91af;"&gt;ModelBindingContext&lt;/span&gt; bindingContext)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (controllerContext == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"controllerContext"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (bindingContext == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"bindingContext"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; controllerContext.HttpContext.Request.AcceptTypes[0];&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The return value from the function will be used to pass in to a parameter in a controller. This allows us to change our controller definition to:&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;ActionResult&lt;/span&gt; List(&lt;span style="color: blue;"&gt;string&lt;/span&gt; oem, [&lt;span style="color: #2b91af;"&gt;ModelBinder&lt;/span&gt;(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;ContentTypeModelBinder&lt;/span&gt;))]&lt;span style="color: blue;"&gt;string&lt;/span&gt; contentType)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//Get the Model for OEM.&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;switch&lt;/span&gt; (contentType)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;case&lt;/span&gt; &lt;span style="color: #a31515;"&gt;"*/*"&lt;/span&gt;:&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;case&lt;/span&gt; &lt;span style="color: #a31515;"&gt;"text/html"&lt;/span&gt;:&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515;"&gt;"PartList.aspx"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;case&lt;/span&gt; &lt;span style="color: #a31515;"&gt;"text/json"&lt;/span&gt;:&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515;"&gt;"PartList.json.aspx"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The magic here is the ModelBinder attribute which is applied to the contentType parameter. This tells the ASP.Net MVC runtime to use our own custom IModelBinder to provide the value for the contentType attribute. &lt;br /&gt;&lt;/P&gt;&lt;br /&gt;&lt;br /&gt;The thing I don't like about this is that we have to use an attribtue in our controller. It is possible to indicate that all instances of a specific type use a specific binder. But I will leave that for a different article.&lt;br /&gt;&lt;br /&gt;Enjoy&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-8303613437608848622?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/8303613437608848622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=8303613437608848622' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/8303613437608848622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/8303613437608848622'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/03/aspnet-mvc-model-binder.html' title='ASP.net MVC Model Binder'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-5319796661351878121</id><published>2009-01-14T15:12:00.008-05:00</published><updated>2009-01-14T16:16:04.891-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><title type='text'>Rendering an ASP.Net Page twice???</title><content type='html'>Not to long ago, I found myself in a peculiar situation which I will explain shortly. Essentially I found myself needing to render an ASP.Net Page, modify an attribute or two and then re-render. I know you must be asking yourself why in the world would you want to do this? Let me explain first why I needed to do this, then we can look at why this doesn't work and how you can hack around the Page model to get it to work.&lt;br /&gt;&lt;br /&gt;The web application I've been working is a LOB application, and printing forms is very important. Furthermore these forms will be provided to our customers customers so we needed to have the utmost control over the form. IE doesn't give you much options when controlling the output. For example using standard methods there is no way to tell IE not to print out the url on the page. The user can modify this setting but relying upon the user to modify their page settings on every print reduces the usability of the application.&lt;br /&gt;&lt;br /&gt;What's a poor web developer to do? &lt;strong&gt;PDF's &lt;/strong&gt;are a portable format and we can have a lot of control over it. Now the challenge became do we learn a whole new document model or can we find a tool to convert Html to PDF's. We opted for converting HTML to PDF for a couple of reasons including:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;We is actually I, and I didn't want to waste any time learning a new document model. My current employer is a small start up and we just don't have the time to waste.&lt;/li&gt;&lt;li&gt;Many of our forms are displayed to the user in a preview mode. So had we gone with not converting the Html we'd have to synchronize our changes, again the "we" is actually "I"...&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;We create the PDF's by overriding the page's Render method. We call a method RenderHtml() which looks like:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;protected&lt;/span&gt; &lt;span style="color:blue;"&gt;virtual&lt;/span&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; RenderHtml(&lt;span style="color:blue;"&gt;string&lt;/span&gt; baseUrl)&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;RemapImageUrl(baseUrl);&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:#2b91af;"&gt;StreamWriter&lt;/span&gt; sw = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;StreamWriter&lt;/span&gt;(&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;MemoryStream&lt;/span&gt;());&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:#2b91af;"&gt;HtmlTextWriter&lt;/span&gt; writer = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HtmlTextWriter&lt;/span&gt;(sw);&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;base&lt;/span&gt;.Render(writer);&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;writer.Flush();&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:#2b91af;"&gt;StreamReader&lt;/span&gt; sr = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;StreamReader&lt;/span&gt;(sw.BaseStream);&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;sr.BaseStream.Position = 0;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;return&lt;/span&gt; sr.ReadToEnd();&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;The RemapImageUrl() provides absolute paths to the images in the document. This could also be done by setting a base; however, in my exact example I had to change the actual URL to get some dynamic images. After we call this method we take the Html and send it to a Html to Pdf converter which then in turn send to the client.&lt;/p&gt;&lt;p&gt;This was working without any issues until like all solutions, a new business requirement came in. We had a form that we sometimes wanted to print a single copy, but in other cases we wanted to print two copies. The second copy would be identical to the first save for a watermark.&lt;/p&gt;&lt;p&gt;I had done something simillar by rendering smaller portions of page indepedantly but in this case, I had a Gridview which requires a form, and needless to say I was trying to jump through so many hurdles guessing at a magic combination of controls and method calls to make this happen&lt;/p&gt;&lt;p&gt;The solution I decided upon was to render my page twice, create two PDF documents then combine them. I know I could have probally done some string parsing, but the documents and format was very fluid at the time, and I simply needed to find a solution and quick. &lt;/p&gt;&lt;p&gt;I figured I could use roughly this code:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; firstDoc=RenderHtml();&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;EnableWatermark(); &lt;span style="color:green;"&gt;//This method turned the water&lt;/span&gt;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;string&lt;/span&gt; secondDoc=RenderHtml();&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;PdfConvert.ConvertFromHtml(firstDoc)&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;.AppendPdf(&lt;span style="color:#2b91af;"&gt;PdfConverter&lt;/span&gt;.ConvertFromHtml(secondDoc));&lt;/p&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;After firing this up, I got an error indicating that a form was already on the page, and there could only be one form. Opening reflector to see what was going on made me cry as I realized what ASP.Net was doing. Now I realize at this point I am far beyond what anyone would consider acceptable use...but lets look real quick why it doesn't work.&lt;/p&gt;&lt;p&gt;Open up reflector and look at the HtmlForm.RenderChildren method this basically calls the Page.OnFormRender then Page.BeginFormRender followed by rendering it's children. It finishes by calling Page.EndFormRender and Page.OnFormPostRender. So let's start with Page.OnFormRender.&lt;/p&gt;&lt;p&gt;This method looks like:&lt;/p&gt;&lt;blockquote&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;internal&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; OnFormRender()&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (&lt;span style="color:blue;"&gt;this&lt;/span&gt;._fOnFormRenderCalled)&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;throw&lt;/span&gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;HttpException&lt;/span&gt;(SR.GetString(&lt;span style="color:#a31515;"&gt;"Multiple_forms_not_allowed"&lt;/span&gt;));&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;._fOnFormRenderCalled = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;._inOnFormRender = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is where we erroring on our second call to the Page's render method. This method makes sense, essentially it ensures there is only form by tracking this at the page level in the _fOnFormRenderCalled variable. Now in the FormPostRender event they are reseting the flag which tracks if a form is activley being rendered; however they do not reset the _fOnFormRenderCalled which is correct. The problem is this variable is never set back to false. Even when the page is finished rendering. &lt;/p&gt;&lt;p&gt;So our solution is to manually reset this private variable using reflection:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;div style="BACKGROUND: #e1d5d7;font-family:Courier New;font-size:10pt;color:black;"   &gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:#2b91af;"&gt;FieldInfo&lt;/span&gt; fi = &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;Page&lt;/span&gt;).GetField(&lt;span style="color:#a31515;"&gt;"_fOnFormRenderCalled"&lt;/span&gt;, &lt;span style="color:navy;"&gt;BindingFlags&lt;/span&gt;.NonPublic &lt;span style="color:navy;"&gt;BindingFlags&lt;/span&gt;.Instance);&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (fi == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;&lt;span style="color:#2b91af;"&gt;LogWriter&lt;/span&gt;.LogError(&lt;span style="color:#a31515;"&gt;"FieldInfo is null verify _fOnFormRenderCalled still exists on the Page object."&lt;/span&gt;);&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;&lt;p style="MARGIN: 0px"&gt;fi.SetValue(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:blue;"&gt;false&lt;/span&gt;);&lt;/p&gt;&lt;/div&gt;&lt;/blockquote&gt;I highly recommend avoiding this, and if anyone has a better solution feel free to share. I'd also write your code defensivley. Well I hope at least someone somwhere finds this helpful, and if you happen to be a dev at Microsoft in the ASP.Net team why not reset these variable before the Page's render method exits.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-5319796661351878121?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/5319796661351878121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=5319796661351878121' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5319796661351878121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/5319796661351878121'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/01/rendering-aspnet-page-twice.html' title='Rendering an ASP.Net Page twice???'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-7891291181557667330</id><published>2009-01-08T11:29:00.003-05:00</published><updated>2009-01-08T11:32:16.628-05:00</updated><title type='text'>Uploading attachments for blog entries on blogger</title><content type='html'>A request was made to upload some of the source code for a previous blog post. Is this possible to do with blogger? If not where is a good place to do this at? Anyone have any suggestions? Free is critical.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-7891291181557667330?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/7891291181557667330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=7891291181557667330' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/7891291181557667330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/7891291181557667330'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2009/01/uploading-attachments-for-blog-entries.html' title='Uploading attachments for blog entries on blogger'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3277088726597339855.post-620410768999506512</id><published>2008-12-12T10:25:00.007-05:00</published><updated>2009-03-19T10:41:31.422-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Logging'/><category scheme='http://www.blogger.com/atom/ns#' term='EntLib'/><title type='text'>Logging to Database With Enterprise Library Part IV - Tieing it all together</title><content type='html'>In my &lt;a href="http://jberke.blogspot.com/2008/12/logging-to-database-with-enterprise_12.html"&gt;last post&lt;/a&gt; we created all the plumbing that we needed to configure our logger. The final step is to create the actual logger. As a side note I want to say that tried to use TDD development for this piece; however, I have learned that TDD is not the greatest choice when your building plugins. I might elaborate on this in the future but anyways.&lt;br /&gt;&lt;br /&gt;To create a custom trace listner for the Enterprise Library you need to derive from CustomTraceListener. You will then need to implement the TraceData function.&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color: #2b91af;"&gt;ConfigurationElementType&lt;/span&gt;(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af;"&gt;CustomTraceListenerData&lt;/span&gt;))]&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;DBAuditLoggerTraceListener&lt;/span&gt; :&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.&lt;span style="color: #2b91af;"&gt;CustomTraceListener&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Write(&lt;span style="color: blue;"&gt;string&lt;/span&gt; message)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NotImplementedException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"This method is not supported"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; WriteLine(&lt;span style="color: blue;"&gt;string&lt;/span&gt; message)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;NotImplementedException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"This method is not supported"&lt;/span&gt;);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; TraceData(&lt;span style="color: #2b91af;"&gt;TraceEventCache&lt;/span&gt; eventCache, &lt;span style="color: blue;"&gt;string&lt;/span&gt; source, &lt;span style="color: navy;"&gt;TraceEventType&lt;/span&gt; eventType, &lt;span style="color: blue;"&gt;int&lt;/span&gt; id, &lt;span style="color: blue;"&gt;object&lt;/span&gt; data)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;AuditLogEntry&lt;/span&gt; ale = data &lt;span style="color: blue;"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;AuditLogEntry&lt;/span&gt;;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (ale == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//Not an audit log entry&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt;;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;IAuditLoggerExpressionGroup&lt;/span&gt; logGroup;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!&lt;span style="color: #2b91af;"&gt;AuditLoggerExpressionCache&lt;/span&gt;.Instance.TryGetValue(ale.AuditCategory, &lt;span style="color: blue;"&gt;out&lt;/span&gt; logGroup))&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//Category not registered&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt;;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af;"&gt;StoredProcedure&lt;/span&gt; sp = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;StoredProcedure&lt;/span&gt;(logGroup.Procedure))&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue;"&gt;string&lt;/span&gt; key &lt;span style="color: blue;"&gt;in&lt;/span&gt; logGroup.Keys)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; sp.AddParameter(key, logGroup.GetValue(key, ale));&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; sp.Execute();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;A couple of things to note, The Stored Procedure class is my own class which I am unable to share; however, all it does is wrap up all the ADO.Net Goodness. It also handles my connection strings which is why I am not passing the connection string in. You should be able to quickly whip up your own ADO.Net code. If you run into issues let me know and I will be glad to help out.&lt;br /&gt;&lt;br /&gt;Basically all we are doing is making sure we have an AuditLogEntry object, then we check if we have created an ExpressionGroup for this AuditCategory. If we have we simply loop through each of the keys in the ExpressionGroup, calling the GetValue method. &lt;br /&gt;&lt;br /&gt;GetValue was needed to ensure that this class didn't have to know about the type parameter in the Expression Group. I'm hopping C#4 with co/contra variance will remove this requirement. Finally we execute the stored procedure.&lt;br /&gt;&lt;br /&gt;The next step is to configure this. If your using an ASP.Net app I'd recommend that you configure your expression Groups in the Global.asax. Also remember to call the Cache() method. If you forget this you will not save the expression group you have created.&lt;br /&gt;&lt;br /&gt;The final step it to add your logger to the EntLib configuration for example:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: #e1d5d7;"&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;loggingConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Logging Application Block&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;tracingEnabled&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;defaultCategory&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Error&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;logWarningsWhenNoCategoriesMatch&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;listeners&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="color: red;"&gt;listenerDataType&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging,&amp;nbsp; Version=3.1.0.0&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="color: red;"&gt;traceOutputOptions&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;None&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;DBAuditLoggerTraceListener, YourAssembly&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;AuditLogger&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;initializeData&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;""&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;formatter&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Text Formatter&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;listeners&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;formatters&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;template&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Timestamp: {timestamp}&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;amp;#xA;&lt;/span&gt;"&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;/span&gt;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging&lt;/span&gt;"&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Text Formatter&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;formatters&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;categorySources&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;switchValue&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;All&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Audit&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;listeners&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;AuditLogger&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;listeners&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;add&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;categorySources&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;loggingConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I just noticed I had left the text formatter in there which I have not used. I am not sure if this is required or not.&lt;br /&gt;&lt;br /&gt;So after all of this what do we have? A logger that will take any AuditLogEntry and execute a stored procedure, with any number of parameters. I hope you find this useful. Please feel free to provide any feedback positive or negative. &lt;br /&gt;&lt;br /&gt;Enjoy!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Update&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I have extracted the &lt;a href="https://cid-917bdf3431085651.skydrive.live.com/browse.aspx/Public/SourceCode" onClick="javascript: pageTracker._trackPageview('/outgoing/SourceCode/EntLibLogger');"&gt;source and posted online&lt;/a&gt;. Please note that this is not tested, so if you run into any issues let me know. When I get caught back up with my day job I will try and finish rounding this out.&lt;br /&gt;&lt;br /&gt;Let me know if this link doesn't work. First time I've used skydrive so I'm not positive I have it all setup right.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3277088726597339855-620410768999506512?l=jberke.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jberke.blogspot.com/feeds/620410768999506512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3277088726597339855&amp;postID=620410768999506512' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/620410768999506512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3277088726597339855/posts/default/620410768999506512'/><link rel='alternate' type='text/html' href='http://jberke.blogspot.com/2008/12/logging-to-database-with-enterprise_58.html' title='Logging to Database With Enterprise Library Part IV - Tieing it all together'/><author><name>Josh Berke</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='04281651418251643231'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>18</thr:total></entry></feed>