Category Archives: C#

ASP.Net MVC: Simple Custom Authorization by Inheriting from the AuthorizeAttribute

Implementing custom authorization to a ASP.Net MVC site can be quite simple if you take advantage of the built-in ActionFilter authorization framework. Here’s how to do it. First, this enumeration describing four levels of access to the site.   // … Continue reading

Posted in ASP.Net, Attributes, C#, MVC | Leave a comment

C#: Export a List of Objects to CSV with LINQ, Attributes, and Generics

Have you ever needed to transform data from in-memory C# objects to a CSV flat-file of a specific format?  Here’s an easy way to get the job done with C#, LINQ, and Generics. First you need the Attribute you will … Continue reading

Posted in Attributes, C#, Generics, LINQ | Leave a comment

C# : String Extension to Parse Enums

It seems to me that there is too much typing involved in parsing a string as an Enum type. Here’s a quick string extension method to turn it into a simpler one liner: public static T EnumParse<T>(this string input, bool … Continue reading

Posted in C# | Leave a comment

ASP.Net MVC: Partially Secured Sites / Switching from HTTPS back to HTTP

Most sites out there have some portions that should be only served via HTTPS, while the remainder can be HTTP, such as account pages and content pages respectively.  This is sometimes called a “partially secured site.” Starting with MVC 2, … Continue reading

Posted in ASP.Net, C#, MVC | 2 Comments

C#: String Extension to Replace Accented Characters

Have you ever wanted to replace “accented” characters in a string with their equivalent English character?  Here’s a string extension that replaces these diacritics within a string for C# 2.0 and up:   public static string ReplaceDiacritics(this string source) { … Continue reading

Posted in ASP.Net, C# | Leave a comment

Creating a SQL CLR User Defined Function

Starting with SQL Server 2005, Microsoft added the awesome ability to reference .Net assemblies from your T-SQL procedures.  Here’s a quick 5 step overview on how to get up and running with your code-based User Defined Function. 1) Create a … Continue reading

Posted in C#, MS SQL Server, T-SQL | Leave a comment