Dynamic Code in C#

co-authored by Joseph Dotson

2_bgWe are working on a project where the data access methodology for the application was defined and provided by the client.  While this approach accomplishes the tasks of accessing data in SQL Server we found that we were duplicating code making small changes to new files but largely repeating code to access new tables in the database.  We decided to look at dynamic code in C# to solve this problem and reduce redundancy in the code base.

Continue reading “Dynamic Code in C#”

Configure Windows Live Writer 2012 to work with SharePoint 2010

2_bgI use Windows Live Writer( for no other reason than it is simple and works) to create blog posts.  I am running Windows 8 and downloaded Live Writer 2012. I then began the seemingly simple steps to configure it to publish directly to SharePoint. First, I started Live Writer and followed the steps in the wizard and received an error stating: “Problem with blog server – server error 2041 occurred. Attempted to perform an unauthorized operation.” Here are the steps to reproduce the error.

Continue reading “Configure Windows Live Writer 2012 to work with SharePoint 2010”

ASP.NET MVC 4.0 Custom Authorize Attribute

DaveI was working on an MVC 4.0 web application that contained some WebAPI controllers.  The requirement was to secure the site using Windows Authentication.  However, only the web pages required security but, the Api controllers did not. I changed the web.config and IIS 7.5 to provide Windows Authentication.  I then added an authorize attribute to my MVC controllers like “[Authorize(Roles = “FooWebUsers”)]”.  Since, the WebAPI controllers did not need security I added the [AllowAnonymous] attribute to those controllers.

I tested the site and discovered the MVC Controllers were properly secured, prompting a login – ok good. Hit one of the API routes in fiddler and got a NT challenge and response or prompt for Login. What’s going on here?  I added [AllowAnonymous] to the API controllers – not working.  After much digging around I found what I wanted by implementing a custom Authorization attribute. Here’s the steps I went through to implement this.

Continue reading “ASP.NET MVC 4.0 Custom Authorize Attribute”

The Template Pattern is Cool

2_bgI find when reviewing code to solve a relatively mundane process with several procedural steps that no pattern is used. The code becomes difficult to support and the intent of the process is muddied by the lack of design. Usually due to two leading factors.  The first factor is lack of experience in the developer – create one class and a few methods with no pattern  and you got it – right? Wrong. This coding style throws your fellow developers to the wolves.

Continue reading “The Template Pattern is Cool”

Beginning RavenDB quick start

2_bgThere has been a lot of buzz in the development community concerning no SQL databases.  That’s right a database used to persist data for an application that involves no SQL period.  How does this work?   How do I construct tables or even perform basic CRUD operations with out SQL? The answer is you don’t.  RavenDB is a schema free database with no concept of tables and rows or mappings or the typical stuff that goes with SQL server or MySQL and so on.  It is a place you can simply dump your application objects into and easily access later.  This alone saves a good deal of time.

Continue reading “Beginning RavenDB quick start”

Easily find duplicate rows using SQL Server 2005+

2_bgFinding duplicate rows in a table can be done very simply by using Common Table Expressions knows as CTE’s along with the SQL Server built-in function ROW_Number() with the <PARTITION BY> and <ORDER BY> arguments found in SQL Server 2005 or later. In the sample below I’m looking for products that exist in the Products table more than once where the ProductName, Quantity, and Price are the same.

Continue reading “Easily find duplicate rows using SQL Server 2005+”