June 15, 2012
Tambourine: CSS: when to use em, px, %,...etc?


If you are new to CSS, like I am, probably you asked yourself whether or not you should be using px, em to define fonts and px or % for width and height.

After some research I found out some interesting answers. But, pls feel free to share yours.

Basically, in theory, using em instead of px

April 16, 2012
Store Session in SQL Server

6:02am  |   URL: http://tmblr.co/Z9-33yJlvsfF
Filed under: dotnet sql server 
April 12, 2012
Using Razor pages within webforms master pages


For those who want to slowly convert any web forms .net proj into MVC 3/4

12:30pm  |   URL: http://tmblr.co/Z9-33yJXrJoq
Filed under: mvc dotnet 
March 27, 2012
MVC 4.0 living side by side with ASP .NET legacy website project (not web application)

Just came across an interesting problem:

I wanted to use MVC 4.0 within a legacy asp .net website project ( not a web application) using Visual Studio 2010 and Razor. I have all MVC versions installed on my machine.

So first I added/registered all MVC assemblies to web.config:

 <add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Abstractions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Also added to the <pages> node:

        <add namespace=”System.Web.Helpers” />
        <add namespace=”System.Web.Mvc” />
        <add namespace=”System.Web.Mvc.Ajax” />
        <add namespace=”System.Web.Mvc.Html” />
        <add namespace=”System.Web.Routing” />
        <add namespace=”System.Web.WebPages” />
        <add tagPrefix=”asp” namespace=”System.Web.UI” assembly=”System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35” />
        <add tagPrefix=”asp” namespace=”System.Web.UI.WebControls” assembly=”System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35” />

And add the correct <httpmodules> :

      <!—<add name=”HttpCompressModule” type=”Ngd.DreamTeam.Football.Web.Compression.HttpModule,Ngd.DreamTeam.Football.Web”/>—>
      <add name=”ScriptModule” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35”/>
      <add name=”UrlRoutingModule” type=”System.Web.Routing.UrlRoutingModule, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”/>

 <modules runAllManagedModulesForAllRequests=”true”>
      <add name=”UrlRoutingModule” type=”System.Web.Routing.UrlRoutingModule, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”/>
      <remove name=”ScriptModule” />
      <add name=”ScriptModule” preCondition=”managedHandler” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35” />

Under <handlers> :

<add name=”UrlRoutingHandler”
            verb=”*” path=”UrlRouting.axd”
                  System.Web, Version=, Culture=neutral,
                  PublicKeyToken=b03f5f7f11d50a3a” />

Then merge the global asax and put the methods all on the global.asax.cs even if they are on the Global.asax .

So Global.asax should look like this :

<%@ Application Language=”C#” CodeFile=”Global.asax.cs” Inherits=”MvcApplication” %>

and the Global.asax.cs like this :

    public partial class MvcApplication : System.Web.HttpApplication
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
            filters.Add(new HandleErrorAttribute());

        public static void RegisterRoutes(RouteCollection routes)

                “Default”, // Route name
                “{controller}/{action}/{id}”, // URL with parameters
                new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }


        protected void Application_Start()



        protected void Session_Start(object sender, EventArgs e)
            // This is the default setting for displaying marketing modals
            SessionManager.SessionManagerInstance.ShowMarketingMessage = true;

        protected void Application_Error(object sender, EventArgs e)
         // all the legacy stuff


        protected void Session_End(object sender, EventArgs e)

        protected void Application_End(object sender, EventArgs e)



Then created a folder Views on the root of the project and put the controllers classes into a folder called Controllers inside the App_Code folder ( If the controllers class are outside the App_Code project MVC will not work).

After all this the project did not work so after a couple of hours I found out that the virtual path ( on VS right button properties on top of the website node) cannot contain the character ‘.’ . My virtual path was something like “project.web” . When I removed this I successfully added MVC 4.0 to a legacy website asp .net project.

January 20, 2012
Google maps API custom Info Box .png issue - iexplorer 9.0

The problem:

Custom Info box does not appear on explorer when a marker is clicked when using google maps API javascript version 3.0 .

The solution:

This issue only happens on explorer and you can sort it out simply removing the opacity filter and the transparency :

#map_canvas div { filter: none !important ; background: transparent !important ; }

December 19, 2011
.net Roles problem

.Net Roles were not working as they were supposed.

I was getting empty Roles on Roles.IsUserInRole and Roles.GetRolesForUser.

[Authorize(Roles = “Administrator”)] was not working properly on the controller action methods. After a little bit of searching I found out that actually it was something missing on the web.config for the Roles to work on IIS7. So the solution simply is adding this web.config stuff under system.webserver -> modules:

 <remove name=”FormsAuthentication” />
      <add name=”FormsAuthentication” type=”System.Web.Security.FormsAuthenticationModule” />
      <remove name=”UrlAuthorization” />
      <add name=”UrlAuthorization” type=”System.Web.Security.UrlAuthorizationModule” />
      <remove name=”DefaultAuthentication” />
      <add name=”DefaultAuthentication” type=”System.Web.Security.DefaultAuthenticationModule” />
      <remove name=”RoleManager” />
      <add name=”RoleManager” type=”System.Web.Security.RoleManagerModule” />


February 15, 2011


This is a message to anybody considering using MVC. Especially 3 with Razor. Do it.

You won’t regret it, it’s fast, beautiful and razor makes it very easy to manage the design side of things.

When I have several e-commerce sites running on it then I’ll know more, so I’ll blog along the way.

(Source: makit)

February 15, 2011
makit.net: .NET Dependency Injection



Recently I’ve been started a new MVC 3 app which is to have lot’s of components so I decided to go down the Dependency Injection route. This, for those who are hazy, is a OO design pattern for decoupling components.

I did some research (read, Google) and thought I’d go with

(Source: makit)

December 5, 2010
Boxing and Unboxing

I found out a lot of articles talking about boxing and unboxing but none of them explains when is good to use this technique.

On Msdn pages I found this definition:

"Boxing is the process of converting a value to the type object or to any interface type implemented by this value type. When the CLR* boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap. Unboxing extracts the value type from the object. Boxing is implicit; unboxing is explicit. The concept of boxing and unboxing underlies the C# unified view of the type system, in which a value of any type can be treated as an object”

The term boxing refers an implicit casting and Unboxing is refers to explicit casting:

int i = 5;
object o = i; // Implicit Casting
int j = (int)o; //Explicit Casting

Assume that you are working in a team of 3 developers each working on a different class. You need 3 classes to be implemented:

MyPoint - Defines a 2D point - Developer 1

My3dPoint - defines a 3D point - Developer 2

MyPrinter - Print the information of the other 2 classes - You

So the code for dev 1 and 2 will be :

//Developer 1

namespace Points{

public class MyPoint{

public int x;

public int y:


public class Starter{

MyPoint p = new MyPoint();

p.x= 4;

p.y = 5;




//Developer 2

namespace Points{

public class My3DPoints{

p.x = 3;

p.y = 4;

p.z =


So the class printer will use boxing and unboxing so its generic for all different class implementations.

namespace Printer
public class MyPrinter
public void PrintInfo(Object o) //Boxing is done here
if(o is MyPoint)
MyPoint p = new MyPoint();
p = (MyPoint)o; // Unboxing
Console.Writeline(“The point is ({0}, {1})”, p.x, p.y);
else if(o is My3DPoint)
My3DPoint p = new My3DPoint();
p = (My3DPoint)o; // Unboxing
Console.Writeline(“The point is ({0}, {1}, {2})”, p.x, p.y, p.z);

This article is an example how to use boxing and unboxing, however you can solve this problem using generics. I'll write a post about that later.

12:45pm  |   URL: http://tmblr.co/Z9-33y1zivLg
Filed under: Boxing Unboxing c .net 
October 31, 2010
Value types and reference types

In this article I will talk about the differences between value types and reference types in c# .

This article assumes a previous knowledge on C# and on the ability to define classes and properties.

To differentiate value types from reference types we can pick an example of each type: Classes and Structs.

We can define a struct simply saying that structs are cut-down classes meaning that structs don’t have finalizers and don’t support inheritance.

Here is an example of a struct:

struct Point
   private int x, y;             // private fields

   public Point (int x, int y)   // constructor
         this.x = x;

         this.y = y;

   public int X                  // property
         get {return x;}

         set {x = value;}

   public int Y
         get {return y;}
         set {y = value;}

There is another difference between structs and classes. Structs are value types and classes are reference types. When a value type instance is created a single space in memory is used to allocated to store the value.  Primitive types such as int, float, bool and char are also value types, and work in the same way. 

Reference types need 2 spaces allocated in memory : a reference to the object and the object itself.

Suppose Form is a class and Point is a struct:

Point p1 = new Point();         // Point is a *struct*
Form f1 = new Form();           // Form is a *class*

In the first case only one space is allocated in memory for p1 whereas, in the second case two spaces are allocated, one for the Form object and other for it’s reference f1.

If we copy both objects using variables:

Point p2 = p1;

Form f2 = f1;

p2 will be an independent copy from p1 with it’s own separated fields. f2 will be a new reference of the object Form, f2 is simply a copy of the reference f1. Now we have 2 references pointing to the same object.

This is really interesting on the passing parameters to methods. As you must know all method parameters are passed by value (by default) in C# meaning that they are implicitly copied when passed to the method.

For value-type parameters this means that an independent is created like we saw with p2 and for reference types this means copying a reference.

Point myPoint = new Point (0, 0);      // a new value-type variable
Form myForm = new Form();              // a new reference-type variable

Test (myPoint, myForm);                // Test is a method defined below

void Test (Point p, Form f)

      p.X = 100;                       // No effect on MyPoint since p is a copy
      f.Text = “Hello, World!”;        // This will change myForm’s caption since

                                       // myForm and f point to the same object
      f = null;                        // No effect on myForm

Assign null to f has no effect because f is a copy of a reference and we have only erased the copy.

 When passing by “reference”, the method interacts directly with the caller’s arguments.  In the example below, you can think of the parameters p and f being replaced by myPoint and myForm:

Point myPoint = new Point (0, 0);      // a new value-type variable
Form myForm = new Form();              // a new reference-type variable

Test (ref myPoint, ref myForm);        // pass myPoint and myForm by reference

void Test (ref Point p, ref Form f)

      p.X = 100;                       // This will change myPoint’s position
      f.Text = “Hello, World!”;        // This will change MyForm’s caption
      f = null;                        // This will nuke the myForm variable!

In this case, assigning null to f also makes myForm null, because this time we’re dealing with the original reference variable and not a copy of it.

Liked posts on Tumblr: More liked posts »