.NET

@aspnet

Enabling CORS only for specific domains in ASP.NET

Enable cross origin resquests only for certain domains in ASP.NET
0
Cross-origin resource sharing (CORS) means that page from other domain can make request to some resource which is on other domain. For example, if you try to invoke some WEB API method which is running on different domain you will get exception in the script. By default CORS are disabled in ASP.NET bot you can easily enable them just by modifying web.config for IIS7 and newer versions pf IIS. ...read more

Enabling GZip and Deflate compression from ASP.NET code

Compress your response on hosts where IIS compression is not supported
0
HTTP compression is a simple way to improve site performance and decrease bandwidth, with no configuration required on the client side. If you test your website through Google PageSpeed Insights, HTTP compression will be one of the points recommended to be used to increase website performance. Luckily for .NET developers IIS supports it out of the box...read more

Easier manipulation with IEnumerable objects

Useful extension methods for working with lists, arrays, dictionaries...
 
0
Working with any collection which implements IEnumerable is pretty easy in C#, plus if you are using LINQ you can easily manipulate with collection data. Recently I was doing some filtering with some in-memory collections and I had to check whether one collection contains same elements as some other collection with elements of the same type...read more

Managed Extensibility Framework (MEF) quick start

Introducing MEF with simple code example application
 
0
Managed Extensibility Framework or MEF is a library introduced in .NET Framework 4 which allows developers to easily create plugin based applications. It lives in System.ComponentModel.Composition namespace and before start working with MEF reference to this assembly needs to be added in a project.It is basically an implementation of IoC (Inversion of Control) pattern with few core functionalities such as assembly loading...read more

Random element of IEnumerable/Array

Random element extension method for IEnumerable/Array
 
0
I don't work with random values very often but recently I had to write some small function that returns random value from an array. It sounded like a good idea to write it as an extension method to make it reusable for other projects...read more

ConcurrentDictionary vs Hashtable.Synchronized

Comparison of collections in multithread environment
 
0
Basically all Dictionary collections in .NET internally implement Hashtable wrapped, so in terms of mechanism they are pretty much the same. The difference is that Dictionary exposes strong types while Hashtable uses object-object keyvalue pair which is much harder to work with because you need to know what is the actual type of the object stored in a key or value. Often casting will probably be required...read more

Convert string to any type that implements TryParse method

String extension method for converting to other value types
0
In many cases serialized data is returned in a form of string although the actual type of data is different. The problem begings when you want to use data in it's original type becaus direct cast is not allowed in C# as it is in VB.net. This is why you have to use TryParse and safely parse the value to it's original type...read more

Creating Visual Studio ProjectTemplate VSIX package

How to create VSIX package for ProjectTemplate
 
0
If you often have projects which setup is pretty much the same you might consider creating ProjectTemplate for Visual Studio.It speeds up development for the project setup, adding references, default configuration .config, content files... Before you start make sure that you have installed Microsoft Visual Studio 2013 SDK (http://www.microsoft.com/en-us/download/details.aspx?id=40758) and Nuget Package Explorer (http://npe.codeplex.com/)I also attached a small dummy project just to help understanding what is written in this article.Skipping to hands on code is always more helpful and faster for me to, so if you are bored by reading, download the attached .7zfile and explore it...read more

Set entry assembly in Unit testing methods

Resolving null entry assembly issue in unit tests
0
Recently I started writing unit tests for a small project I keep in my visualstudio online TFS repository. After few test done I run into an issue. Since this project heavily relies on Reflection and dynamic assembly loading, main class constructor at one point is calling ...read more

Avoiding high processor load in long running loops

Keep processor not overloaded with long running loops
0
When having a long running loop which you are not sure when it is going to end you will probably have to create a loop in a separate loop and on every iterration you will check whether some condition is true and exit the loop. Let's say you want to execute some piece of code after some specific time, let's say after one minute or everyday at specific time (common scenario in windows services). You can do it really simple with Timer class and just few lines of code as the code below. ...read more

JavaScript

read more

SQL/T-SQL

read more

Umbraco CMS

read more

PowerShell

read more