<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Mariano@Blog!</title><subtitle type="html">.NET and other interesting stuff.</subtitle><id>http://weblogs.asp.net/marianos/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/marianos/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2007-11-01T17:14:30Z</updated><entry><title>Workshop de desarrollo de aplicaciones Windows Store</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2012/10/04/workshop-de-desarrollo-de-aplicaciones-windows-store.aspx" /><id>http://weblogs.asp.net/marianos/archive/2012/10/04/workshop-de-desarrollo-de-aplicaciones-windows-store.aspx</id><published>2012-10-04T14:57:11Z</published><updated>2012-10-04T14:57:11Z</updated><content type="html">&lt;p&gt;La semana próxima con mi compañero de &lt;a href="http://www.lagash.com/"&gt;Lagash&lt;/a&gt;, &lt;a href="http://shockbyte.net"&gt;RodoF&lt;/a&gt;, estaremos dando un Workshop de desarrollo de aplicaciones &lt;a href="http://es.wikipedia.org/wiki/Windows_Store"&gt;Windows Store&lt;/a&gt; en el &lt;a href="http://www.mug.org.ar/"&gt;MUG&lt;/a&gt; los dias 10, 11, y 12 de Octubre.&lt;br /&gt;&lt;br /&gt;Durante esos 3 dias haremos un repaso de la plataforma &lt;a href="http://windows.microsoft.com/"&gt;Windows 8&lt;/a&gt;, el diseño de aplicaciones &lt;a href="http://en.wikipedia.org/wiki/Modern_UI_(design_language)"&gt;Modern UI&lt;/a&gt;, y las herramientas y lenguajes que tenemos disponibles para desarrollarlas, todo esto con mucha practica.&lt;br /&gt;&lt;br /&gt;!Y como bonus al final del workshop se ofrecerá la posibilidad e subir las aplicaciones que se desarrollen al &lt;a href="http://es.wikipedia.org/wiki/Windows_Store"&gt;Windows Store&lt;/a&gt;!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.mug.org.ar/Eventos/3823.aspx"&gt;Aquí&lt;/a&gt; pueden ver el detalle del curso y registrarse.&lt;br /&gt;&lt;br /&gt;Los esperamos!!&lt;/p&gt;
&lt;p&gt;&lt;img style="margin: 5px" alt="" src="http://shockbyte.files.wordpress.com/2012/10/logowin8.jpg?w=604&amp;h=135" /&gt;&lt;/p&gt;
&lt;p style="color:#008;text-align:right;"&gt;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=9043657" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /><category term="Eventos" scheme="http://weblogs.asp.net/marianos/archive/tags/Eventos/default.aspx" /><category term="Metro" scheme="http://weblogs.asp.net/marianos/archive/tags/Metro/default.aspx" /><category term="Windows 8" scheme="http://weblogs.asp.net/marianos/archive/tags/Windows+8/default.aspx" /></entry><entry><title>Día del Programador. Evento MUG</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2012/09/12/d-237-a-del-programador-evento-mug.aspx" /><id>http://weblogs.asp.net/marianos/archive/2012/09/12/d-237-a-del-programador-evento-mug.aspx</id><published>2012-09-12T15:02:38Z</published><updated>2012-09-12T15:02:38Z</updated><content type="html">&lt;p&gt;Hola a todos.&lt;br /&gt;&lt;br /&gt;Les acerco los &lt;a href="http://sdrv.ms/RRRy2j"&gt;materiales&lt;/a&gt; de la charla de ayer organizada por el &lt;a href="http://www.mug.org.ar"&gt;MUG&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Gracias por participar.&lt;/p&gt;
&lt;p&gt;Nos leemos!!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8913764" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /><category term="ASP.NET" scheme="http://weblogs.asp.net/marianos/archive/tags/ASP.NET/default.aspx" /><category term="ASP.NET MVC3" scheme="http://weblogs.asp.net/marianos/archive/tags/ASP.NET+MVC3/default.aspx" /><category term="Eventos" scheme="http://weblogs.asp.net/marianos/archive/tags/Eventos/default.aspx" /><category term="Javascript" scheme="http://weblogs.asp.net/marianos/archive/tags/Javascript/default.aspx" /></entry><entry><title>Desarrollo de Aplicaciones Metro para Windows 8 con Visual Studio 2012 - Charla MUG</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2012/08/01/desarrollo-de-aplicaciones-metro-charla-mug.aspx" /><id>http://weblogs.asp.net/marianos/archive/2012/08/01/desarrollo-de-aplicaciones-metro-charla-mug.aspx</id><published>2012-08-01T12:52:00Z</published><updated>2012-08-01T12:52:00Z</updated><content type="html">Hola a Todos.
&lt;p&gt;Les dejo el &lt;a href="http://sdrv.ms/Mbyo1q"&gt;link&lt;/a&gt; para descargar las PPTs y Fuentes de la charla sobre desarrollo de aplicaciones Metro que presentamos &lt;a href="http://shockbyte.net"&gt;RodoF&lt;/a&gt; Guillermo y Yo en el &lt;a href="http://www.mug.org.ar"&gt;MUG.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Gracias por participar.&lt;/p&gt;
&lt;p&gt;Nos leemos!!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8806509" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /><category term="Eventos" scheme="http://weblogs.asp.net/marianos/archive/tags/Eventos/default.aspx" /><category term="Javascript" scheme="http://weblogs.asp.net/marianos/archive/tags/Javascript/default.aspx" /><category term="Metro" scheme="http://weblogs.asp.net/marianos/archive/tags/Metro/default.aspx" /><category term="Windows 8" scheme="http://weblogs.asp.net/marianos/archive/tags/Windows+8/default.aspx" /></entry><entry><title>RUN 2012 Buenos Aires - Desarrollando para dispositivos móviles con HTML5 y ASP.NET</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2012/03/22/run-2012-buenos-aires-desarrollando-para-dispositivos-m-243-viles-con-html5-y-asp-net.aspx" /><id>http://weblogs.asp.net/marianos/archive/2012/03/22/run-2012-buenos-aires-desarrollando-para-dispositivos-m-243-viles-con-html5-y-asp-net.aspx</id><published>2012-03-22T19:04:00Z</published><updated>2012-03-22T19:04:00Z</updated><content type="html">&lt;p&gt;El próximo Viernes 23 de Marzo a las 8:30 hs en la Universidad Católica Argentina se realizará una nueva edición del Run en Buenos Aires, el evento Microsoft más importante del año.&lt;/p&gt;  &lt;p&gt;Particularmente, voy a estar junto con Rodolfo Finochietti e Ignacio Lopez presentando nuestra charla “Desarrollando para dispositivos móviles con HTML5 y ASP.NET” donde voy a presentar algunas novedades de ASP.NET MVC 4.&lt;/p&gt;  &lt;p&gt;Esta es la agenda completa de sesiones para Desarrolladores:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Keynote: Un mundo de dispositivos conectados. &lt;/li&gt;    &lt;li&gt;Aplicaciones al alcance de tu mano: Windows Phone – &lt;strong&gt;Ariel Schapiro, Miguel Saez.&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;Desarrollando para dispositivos móviles con HTML5 y ASP.NET &lt;strong&gt;– Ignacio Lopez, Rodolfo Finochietti, Mariano Sánchez.&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;Servicios en la Nube con Windows Azure – &lt;strong&gt;Matias Woloski, Johnny Halife.&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;Desarrollo Estilo Metro en Windows 8 – &lt;strong&gt;Martin Salias, Miguel Saez, Adrian Eidelman, Rubén Altman, Damian Martinez Gelabert&lt;/strong&gt;.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;El evento es gratuito, con registro previo: &lt;a href="http://bit.ly/registracionrunargdev" mce_href="http://bit.ly/registracionrunargdev"&gt;http://bit.ly/registracionrunargdev&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;&lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8358333" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term="ASP.NET MVC 4" scheme="http://weblogs.asp.net/marianos/archive/tags/ASP.NET+MVC+4/default.aspx" /><category term="Eventos" scheme="http://weblogs.asp.net/marianos/archive/tags/Eventos/default.aspx" /></entry><entry><title>Extendiendo ASP.NET MVC 3 – Model Binders</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2012/03/13/extendiendo-asp-net-mvc-3-model-binders.aspx" /><id>http://weblogs.asp.net/marianos/archive/2012/03/13/extendiendo-asp-net-mvc-3-model-binders.aspx</id><published>2012-03-13T15:19:00Z</published><updated>2012-03-13T15:19:00Z</updated><content type="html">&lt;p&gt;Como vimos en el post anterior Model Binding es el proceso de transformar los datos que se obtienen al momento del Request (como por ejemplo valores de Forms, Query Strings, etc.) en Modelos.&lt;/p&gt;  &lt;p&gt;Por cada valor que se quiera obtener para crear un Modelo, se deben seguir mínimamente los siguientes pasos: obtener el valor buscado utilizando los Value Providers, mantener el estado de ese valor para poder utilizarlo en el caso de necesitarlo (por ejemplo para mostrar un error), y aplicar las validaciones necesarias para asegurarnos que el valor obtenido cumple con los requisitos para pertenecer a nuestro Modelo.&lt;/p&gt;  &lt;p&gt;En nuestro siguiente ejemplo vamos a ver una implementación de un Model Binder que se utiliza para crear una instancia de la clase Frase, la cual tiene una referencia a la clase Autor. Este Model Binder se encarga de obtener la instancia de Autor correspondiente al código que se envía en el Request y termina generando una instancia de la clase Frase con la referencia al Autor obtenido.&lt;/p&gt;  &lt;p&gt;Veamos el código de las clases Frase y Autor:&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;div style="border: 1px solid rgb(0, 0, 128); font-family: ;"&gt;   &lt;div style="padding: 2px 5px; overflow: auto; background-color: rgb(243, 243, 243);"&gt;&lt;font face="Courier New"&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;&lt;font style="font-size: 10pt;"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;class&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Frase&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;{            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; Frase()            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {             &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Comentarios = &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;List&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Comentario&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;&amp;gt;();            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Votos = &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;List&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Voto&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;&amp;gt;();            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;int&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; FraseId { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Required&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(ErrorMessage=&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#a31515"&gt;"Si no vas a decir nada no molestes che!!!"&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;)]            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; Texto { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&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;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;List&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Voto&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt; Votos { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;List&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Comentario&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt; Comentarios { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;int&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; AutorId { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Autor&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; Autor { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;int&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; CantidadVotos            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {             &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; CalcularVotos(); }            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;private&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;int&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; CalcularVotos()            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {             &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; meGusta = Votos.Where(x =&amp;gt; x.MeGusta).Count();            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; noMeGusta = Votos.Where(x =&amp;gt; !x.MeGusta).Count();            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; meGusta - noMeGusta;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }             &lt;br&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;font color="#000000" size="2" face="Courier New"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;div style="border: 1px solid rgb(0, 0, 128); font-family: ;"&gt;   &lt;div style="padding: 2px 5px; overflow: auto; background-color: rgb(243, 243, 243);"&gt;&lt;font face="Courier New"&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;&lt;font style="font-size: 10pt;"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;class&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Autor&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;{            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;int&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; AutorId { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; Nombre { &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;; }            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;List&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Frase&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt; Frases {&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;get&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;set&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;;}            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; Autor()            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {             &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Frases = &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;List&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Frase&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt;();            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }             &lt;br&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Nuestro Model Binder se va a encargar de generar una instancia de la clase Frase, con la propiedad Texto y la instancia de Autor completas. Para ello va a obtener del Request, mediante el Value Provider, los valores para la clave “Texto”, y para la clave “Autor”. Con el valor de Autor, obtendremos la instancia correspondiente para asignarla a la Frase. Si se fijan en la definición de la clase Frase, van a ver que el campo “Texto” es un campo requerido el cual posee un mensaje de error especial. Esta Metadata de validación va a ser utilizada por el Model Binder para validar la completitud del valor.    &lt;br&gt;Dicho esto, veamos el código del Model Binder:    &lt;br&gt;&lt;/p&gt;  &lt;div style="border: 1px solid rgb(0, 0, 128); font-family: ;"&gt;   &lt;div style="padding: 2px 5px; overflow: auto; background-color: rgb(243, 243, 243);"&gt;&lt;font face="Courier New"&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;&lt;font style="font-size: 10pt;"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;class&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;FraseModelBinder&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; : &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;IModelBinder&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;{            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;object&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; BindModel(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ControllerContext&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; controllerContext,            &lt;br&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;&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;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ModelBindingContext&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; bindingContext)            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; frase = &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Frase&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;();            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; frase.Texto = Get&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt;(controllerContext, bindingContext, &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#a31515"&gt;"Texto"&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;);            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; nombreAutor = Get&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt;(controllerContext, bindingContext, &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#a31515"&gt;"Autor"&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;);            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; autor = &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;FrasesService&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;.ObtenerAutor(nombreAutor);            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; frase.Autor = autor;             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; frase;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;private&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; TModel Get&amp;lt;TModel&amp;gt;(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ControllerContext&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; controllerContext,            &lt;br&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;&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;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ModelBindingContext&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; bindingContext,            &lt;br&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;&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;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; name)            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {             &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;// Obtengo el Valor del ValueProvider&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ValueProviderResult&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; valueProviderResult = bindingContext.ValueProvider.GetValue(name);            &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;// Genero el Model State con el valor. Esto me permite devolver el valor para nuevos bindings en caso de que &lt;/font&gt;&lt;/span&gt;          &lt;br&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;// sea invalido, (Ej: Valores string en propiedades int).&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ModelState&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; modelState = &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ModelState&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; { Value = valueProviderResult };            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bindingContext.ModelState.Add(name, modelState);             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;// Convierto al tipo especifico&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; model = (TModel)valueProviderResult.ConvertTo(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;typeof&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;(TModel));            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;// Obtengo la metadata de la propiedad, necesaria para la validacion&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; metadata = bindingContext.PropertyMetadata[name];            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; metadata.Model = model;             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;// Usando la Metadada y el valor corro las validaciones&lt;/font&gt;&lt;/span&gt;           &lt;br&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;IEnumerable&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ModelValidator&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;gt; validators = &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ModelValidatorProviders&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;.Providers.GetValidators(metadata, controllerContext);            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;foreach&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; (&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; validator &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;in&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; validators)            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;foreach&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; (&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; validatorResult &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;in&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; validator.Validate(bindingContext.Model))            &lt;br&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; modelState.Errors.Add(validatorResult.Message);             &lt;br&gt;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; model;            &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }             &lt;br&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Como primera observación podemos ver que los Model Binders deben implementar la Interfaz IModelBinder, la cual posee el método BindModel que recibe como parámetros la información de contexto del controller dentro de una instancia de la clase ControllerContext y también la información de contexto del proceso de Binding dentro de una instancia de la clase ModelBindingContext.    &lt;br&gt;Con estos dos parámetros se puede acceder a todo lo necesario para realizar Model Binding: Value Providers, Model State, Metadata de Modelos, etc.     &lt;br&gt;Nuestro Model Binder posee un método privado Get, el cual se encarga de obtener un valor que se corresponda al nombre de una clave.&lt;/p&gt;  &lt;p&gt;Este método posee cinco partes interesantes, la primera donde se usa el Value Provider para obtener el valor el cual viene wrapeado en una instancia de la clase ValueProviderResult, la segunda donde se genera el Model State para mantener el valor que se obtuvo para poder ser utilizado según necesidad (por ejemplo si esperamos un entero y recibimos un string, vamos a querer que ese string se mantenga para poder presentarse en la pagina nuevamente en el mismo input donde fue ingresado junto con el mensaje de error correspondiente), la tercera donde se toma el valor obtenido y se transforma al tipo esperado, la cuarta donde se obtiene la Metadata del Modelo para la propiedad que corresponde la clave, y la quinta donde se utiliza la información de validación obtenida en la metadata para realizar las validaciones y en el caso de que no pasen almacenar los errores en el ModelState instanciado para la clave que estamos buscando.&lt;/p&gt;  &lt;p&gt;Una vez completada la obtención de valores y construcción del Modelo, el método BindModel devuelve la instancia de Frase con el Texto y el Autor completos.&lt;/p&gt;  &lt;p&gt;Con esto, tenemos completo nuestro Custom Model Binder para ahora, como hicimos con el Custom Value Provider, el siguiente paso es “decirle” a MVC que existe un nuevo Model Binder y que tiene que ser considerado para ser utilizado al momento de realizar el Binding para la clase Frase. Esto se realiza dentro del Global.Axasx, como se muestra en el siguiente snippet:&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;div style="border: 1px solid rgb(0, 0, 128); font-family: ;"&gt;   &lt;div style="padding: 2px 5px; overflow: auto; background-color: rgb(243, 243, 243);"&gt;&lt;font face="Courier New"&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;&lt;font style="font-size: 10pt;"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; RegisterModelBinders()            &lt;br&gt;{             &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ModelBinders&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;.Binders.Add(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;typeof&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Frase&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;), &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;FraseModelBinder&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;());            &lt;br&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt; &lt;/div&gt;  &lt;div style="font-family: ;"&gt;&amp;nbsp;&lt;/div&gt;  &lt;p&gt;&lt;font size="2"&gt;Con este último punto, nuestra aplicación esta lista para utilizar nuestro nuevo ModelBinder!&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;En &lt;/font&gt;&lt;font size="2"&gt;la próxima semana continuaremos con el siguiente punto de extensibilidad: View Engines.      &lt;br&gt;      &lt;br&gt;Nos leemos!!&lt;span style="font-family: ;"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8344610" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /><category term="ASP.NET MVC3" scheme="http://weblogs.asp.net/marianos/archive/tags/ASP.NET+MVC3/default.aspx" /></entry><entry><title>Extendiendo ASP.NET MVC 3</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2012/02/22/extendiendo-asp-net-mvc-3.aspx" /><id>http://weblogs.asp.net/marianos/archive/2012/02/22/extendiendo-asp-net-mvc-3.aspx</id><published>2012-02-22T18:56:00Z</published><updated>2012-02-22T18:56:00Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;Buenas!&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;En esta serie de post vamos a estar revisando con ejemplos los principales puntos de extensibilidad de ASP.NET MVC 3.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;La lista a revisar es la siguiente:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;•Model:&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Value Providers &lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Model Binders&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font size="2"&gt;•View:&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–View Engines&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Html Helpers&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Razor Helpers&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font size="2"&gt;•Controller:&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Action Name Selectors&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Action Methods Selectors&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Action Filters&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Exceptions Filters&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;–Custom Results&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font size="2"&gt;Así que empecemos!!&lt;/font&gt;&lt;/p&gt;  &lt;h3&gt;Value Providers:&lt;/h3&gt;  &lt;p&gt;&lt;font size="2"&gt;Model Binding es el proceso de transformar los datos que se obtienen&amp;nbsp;al momento del Request&amp;nbsp;(como por ejemplo valores de Forms, Query Strings, etc.) en Modelos.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Para esto durante el Model Binding es necesario contar con un mecanismo que nos permita entender de donde provienen los datos para poder acceder a estos y utilizarlos para crear o actualizar objetos del Modelo. Este mecanismo son los &lt;strong&gt;Value Providers&lt;/strong&gt;.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;El propósito de un Value Provider es simple, proveer acceso a la información que se puede utilizar para el proceso de Model Binding. MVC posee varios Value Providers que el Default Model Binder utiliza, entre estos FormValueProvider, QueryStringValueProvider y RouteDataValueProvider.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;En nuestro ejemplo crearemos un Value Provider que accede a las Cookies para obtener valores.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Para esto, vamos a agregar una nueva clase llamada CookieValueProvider que implementa la interfaz &lt;strong&gt;IValueProvider&lt;/strong&gt;.       &lt;br&gt;Esta interfaz posee dos métodos:       &lt;br&gt;- &lt;strong&gt;ContainsPrefix&lt;/strong&gt;: Se utiliza para determinar si el Value Provider puede obtener los valores solicitados bajo ese prefijo / clave. Si puede, MVC lo va a utilizar para obtener el valor utilizando el método GetValue. Devuelve un boolean.       &lt;br&gt;- &lt;strong&gt;GetValue&lt;/strong&gt;: Obtiene le valor a través de la clave solicitada. Devuelve una instancia de &lt;strong&gt;ValueProviderResult&lt;/strong&gt; la cual es básicamente un Wrapper del valor, que se encarga de resolver algunas cuestiones como conversiones o manejo de cultura.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;La siguiente seria nuestra implementación de &lt;strong&gt;CookieValueProvider&lt;/strong&gt;. Al construirse utiliza la colección de HttpCookies para crear un diccionario donde se almacenan los valores de las cookies indexadas por sus claves. Con esta información, el método ContainsPrefix verifica si en la colección existe la clave. Si existe devuelve True y entonces MVC va a utilizar este Value Provider para obtener el valor a través el método GetValue, el cual va a acceder al diccionario de valores de cookies para obtener el valor y devolverlo como una instancia de &lt;strong&gt;ValueProviderResult&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="background: rgb(238, 236, 225); margin-top: 0in; margin-right: 0in; margin-left: 0in; list-style-type: disc; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-background-themecolor: background2;" class="MsoNormal"&gt;&lt;span style="font-family: ; mso-ansi-language: en-us; mso-fareast-language: en-us;"&gt;&lt;font style="font-size: 10pt;" color="#000000" face="Consolas"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="background: white; margin-top: 0in; margin-right: 0in; margin-left: 0in; list-style-type: disc; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;" class="MsoNormal"&gt;&lt;span style="font-family: ; mso-ansi-language: en-us; mso-fareast-language: en-us;"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 10pt;" color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;pre style="background: rgb(238, 236, 225); margin: 0in 0in 0pt; list-style-type: disc; mso-background-themecolor: background2;"&gt;&lt;span style="font-family: ; mso-ansi-language: es-ar;" lang="ES-AR"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 10pt;" color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="background: rgb(238, 236, 225); margin: 0in 0in 0pt; list-style-type: disc; mso-background-themecolor: background2;"&gt;&lt;span style="font-family: ;"&gt;&lt;font style="font-size: 10pt;" color="#000000" face="Consolas"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;div style="font-family: ;"&gt;
  &lt;div style="padding: 2px 5px; overflow: auto; background-color: rgb(243, 243, 243);"&gt;&lt;font face="Courier New"&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;&lt;font style="font-size: 10pt;"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;class&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;CookieValueProvider&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; : &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;IValueProvider&lt;/font&gt;&lt;/span&gt;

        &lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;{
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;private&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Dictionary&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;&amp;gt; _cookiesKeys = 
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;Dictionary&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;&amp;lt;&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;, &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;&amp;gt;();
          &lt;br&gt;

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; CookieValueProvider(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;HttpCookieCollection&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; cookieCollection)
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;foreach&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; (&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; cookieName &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;in&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; cookieCollection)
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; cookie = cookieCollection.Get(cookieName);
          &lt;br&gt;

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;foreach&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; (&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; key &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;in&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; cookie.Values.AllKeys)
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {

          &lt;br&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;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;if&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; (key != &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;null&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; &amp;amp;&amp;amp; !_cookiesKeys.ContainsKey(key))
          &lt;br&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _cookiesKeys.Add(key, cookie.Values.Get(key));

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

          &lt;br&gt;

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;bool&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; ContainsPrefix(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; prefix)
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; containsPrefix = _cookiesKeys.Keys.Any(x =&amp;gt; x == prefix);
          &lt;br&gt;

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; containsPrefix;
          &lt;br&gt;

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

          &lt;br&gt;

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ValueProviderResult&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; GetValue(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;string&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; key)
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;var&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; value = _cookiesKeys[key];
          &lt;br&gt;

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; value != &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;null&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; ?
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ValueProviderResult&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(value, value, &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;CultureInfo&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt;.CurrentUICulture) 
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;null&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;;
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

          &lt;br&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;font size="2"&gt;Con esto, tenemos completo nuestro Custom Value Provider para acceder a las Cookies y obtener valores desde allí. Ahora el siguiente paso es “decirle” a MVC que existe un nuevo Value Provider y que tiene que ser considerado para ser utilizado al momento de obtener valores durante el proceso de Model Binding. 
    &lt;br&gt;

    &lt;br&gt;Para esto necesitamos implementar una clase que derive de la clase abstracta &lt;strong&gt;ValueProviderFactory &lt;/strong&gt;e implemente el método &lt;strong&gt;GetValueProvider&lt;/strong&gt;. Esta fábrica se va encargar de devolver nuestro nuevo Value Provider construido basándose en la información de contexto. 

    &lt;br&gt;La siguiente seria nuestra implementación de la CookieValueProviderFactory, la cual en el método &lt;strong&gt;GetValueProvider&lt;/strong&gt; se encarga de devolver una nueva instancia de CookieValueProvider, pasándole por parámetro de constructor la colección de Cookies que se están utilizando en el Request.&lt;/font&gt;&lt;/p&gt;

&lt;div style="font-family: ;"&gt;
  &lt;div style="padding: 2px 5px; overflow: auto; background-color: rgb(243, 243, 243);"&gt;&lt;font face="Courier New"&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;&lt;font style="font-size: 10pt;"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;class&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;CookieValueProviderFactory&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; : &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ValueProviderFactory&lt;/font&gt;&lt;/span&gt;

        &lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;{
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;public&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;override&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;IValueProvider&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; GetValueProvider(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ControllerContext&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; controllerContext)
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;return&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;CookieValueProvider&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt;(controllerContext.HttpContext.Request.Cookies);
          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }

          &lt;br&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;font size="2"&gt;&lt;/font&gt;

&lt;p&gt;&lt;font size="2"&gt;Una vez creada nuestra fabrica, el ultimo punto es registrarla dentro de la coleción de fábricas de Value Providers que posee MVC. Esto lo podemos hacer dentro del archivo Global.asax, en el método Application_Start, como se ve a continuación:&lt;/font&gt;&lt;/p&gt;
&lt;span style="font-family: ; mso-ansi-language: es-ar;" lang="ES-AR"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 10pt;" color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="mso-ansi-language: es-ar;" lang="ES-AR"&gt;&lt;/span&gt;&lt;span style="font-family: ; mso-ansi-language: es-ar;" lang="ES-AR"&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 10pt;" color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="mso-ansi-language: es-ar;" lang="ES-AR"&gt;&lt;/span&gt;&lt;span style="font-family: ;"&gt;&lt;font style="font-size: 10pt;" color="#000000" face="Consolas"&gt;&lt;/font&gt;&lt;/span&gt;

&lt;div style="font-family: ;"&gt;
  &lt;div style="padding: 2px 5px; overflow: auto; background-color: rgb(243, 243, 243);"&gt;&lt;font face="Courier New"&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;&lt;font style="font-size: 10pt;"&gt;protected&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt; Application_Start()
          &lt;br&gt;{

          &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;//....&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;

        &lt;br&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;ValueProviderFactories&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#000000"&gt;.Factories.Add(&lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#0000ff"&gt;new&lt;/font&gt;&lt;/span&gt;&lt;font color="#000000"&gt; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#2b91af"&gt;CookieValueProviderFactory&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font style="font-size: 10pt;"&gt;&lt;font color="#000000"&gt;());&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;span&gt;&lt;font style="background-color: rgb(243, 243, 243);" color="#008000"&gt;//....&lt;/font&gt;&lt;/span&gt;

        &lt;br&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;font size="2"&gt;Con este último punto, nuestra aplicación esta lista para utilizar nuestro nuevo ValueProvider!&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;En &lt;/font&gt;&lt;font size="2"&gt;la próxima semana continuaremos con el siguiente punto de extensibilidad: Model Binders. 
    &lt;br&gt;

    &lt;br&gt;Nos leemos!!&lt;span style="font-family: ;"&gt;&lt;font face="Consolas"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8308524" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /><category term="ASP.NET MVC3" scheme="http://weblogs.asp.net/marianos/archive/tags/ASP.NET+MVC3/default.aspx" /></entry><entry><title>Extendiendo MVC 3 - Charla MUG</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2012/02/17/extendiendo-mvc-3-charla-mug.aspx" /><id>http://weblogs.asp.net/marianos/archive/2012/02/17/extendiendo-mvc-3-charla-mug.aspx</id><published>2012-02-17T17:58:00Z</published><updated>2012-02-17T17:58:00Z</updated><content type="html">&lt;p&gt;Les acerco el &lt;a href="http://weblogs.asp.net/blogs/marianos/FrasesDeTodos.zip" target="_blank" mce_href="http://weblogs.asp.net/blogs/marianos/FrasesDeTodos.zip"&gt;código fuente&lt;/a&gt; de la demo de la charla Extendiendo MVC 3 que presentamos en el &lt;a href="http://www.mug.org.ar/" target="_blank" mce_href="http://www.mug.org.ar/"&gt;MUG&lt;/a&gt; junto con &lt;a href="http://weblogs.shockbyte.com.ar/rodolfof/Default.aspx" target="_blank" mce_href="http://weblogs.shockbyte.com.ar/rodolfof/Default.aspx"&gt;RodoF&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Gracias a los que vinieron y espero que les sea útil.&lt;/p&gt;&lt;p&gt;Saludos!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8298682" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /><category term="ASP.NET" scheme="http://weblogs.asp.net/marianos/archive/tags/ASP.NET/default.aspx" /><category term="ASP.NET MVC3" scheme="http://weblogs.asp.net/marianos/archive/tags/ASP.NET+MVC3/default.aspx" /></entry><entry><title>Code Camp 2011  - Entity Framework 4.1 - Code First desde las trincheras</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2011/10/15/code-camp-2011-entity-framework-4-1-desde-las-trincheras.aspx" /><id>http://weblogs.asp.net/marianos/archive/2011/10/15/code-camp-2011-entity-framework-4-1-desde-las-trincheras.aspx</id><published>2011-10-15T09:44:00Z</published><updated>2011-10-15T09:44:00Z</updated><content type="html">&lt;p mce_keep="true"&gt;Mañana voy a estar presentando la charla &lt;a title="EF 4.1 - Code First desde las trincheras" href="http://www.codecamp.com.ar/sesiones/entity-framework-41-code-first-desde-las-trincheras" target="_blank" mce_href="http://www.codecamp.com.ar/sesiones/entity-framework-41-code-first-desde-las-trincheras"&gt;Entity Framework 4.1 - Code First desde las trincheras &lt;/a&gt;en el &lt;a href="http://weblogs.asp.net/controlpanel/blogs/www.codecamp.com.ar" mce_href="http://weblogs.asp.net/controlpanel/blogs/www.codecamp.com.ar"&gt;CodeCamp 2011&lt;/a&gt;&amp;nbsp;de Buenos Aires.&lt;/p&gt;
&lt;p mce_keep="true"&gt;A partir de el Lunes van a estar disponible en este Blog todos los recursos de la charla.&lt;/p&gt;&lt;p mce_keep="true"&gt;Nos vemos allá!!!&lt;/p&gt;&lt;p mce_keep="true"&gt;Update: PPT y Sources &lt;a title="Source" href="https://rapidshare.com/files/2222886157/EF_4.1_Code_First_desde_las_Trincheras.rar" target="_blank" mce_href="https://rapidshare.com/files/2222886157/EF_4.1_Code_First_desde_las_Trincheras.rar"&gt;acá&lt;/a&gt;.&lt;/p&gt;

&lt;a href="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032493728&amp;amp;Culture=es-AR" target="_blank"&gt;
    &lt;img style="width: 300px; height: 250px;" alt="Banner CodeCamp 300x250" src="http://www.codecamp.com.ar/themes/codecamp/content/media/misc/ban_ar-uru_codecamp_300x250.jpg"&gt;
&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7993656" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="Entity Framework" scheme="http://weblogs.asp.net/marianos/archive/tags/Entity+Framework/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /></entry><entry><title>Enamorandose de Entity Framework 4 - CodeCamp 2010</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2010/09/04/enamorandose-de-entity-framework-4-codecamp-2010.aspx" /><id>http://weblogs.asp.net/marianos/archive/2010/09/04/enamorandose-de-entity-framework-4-codecamp-2010.aspx</id><published>2010-09-04T03:50:00Z</published><updated>2010-09-04T03:50:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;Mañana, con mi colega &lt;A href="http://agileculture.net/lboffi" target=_blank mce_href="http://agileculture.net/lboffi "&gt;Leandro Boffi&lt;/A&gt;, vamos a estar presentando la charla &lt;A href="http://www.codecamp.com.ar/enamorandose-de-entity-framework-4.0.aspx" target=_blank mce_href="http://www.codecamp.com.ar/enamorandose-de-entity-framework-4.0.aspx"&gt;Enamorandose de Entity Framework 4&lt;/A&gt; donde repasaremos los nuevos features de Entity Framework 4 en el &lt;A href="http://www.codecamp.com.ar/" target=_blank mce_href="http://www.codecamp.com.ar/"&gt;CodeCamp 2010&lt;/A&gt; de Buenos Aires.&lt;/P&gt;
&lt;P mce_keep="true"&gt;A partir de el Lunes va a estar disponible en este Blog todos los recursos que utilizamos para las demos.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Los esperamos!!&lt;/P&gt;
&lt;P mce_keep="true"&gt;Update: &lt;A href="http://cid-66ab8c7d175a1c6d.office.live.com/self.aspx/CodeCamp2010/Enamorandose%20de%20Entity%20Framewor%204%20-%20CodeCamp%202010.rar" target=_blank mce_href="http://cid-66ab8c7d175a1c6d.office.live.com/self.aspx/CodeCamp2010/Enamorandose%20de%20Entity%20Framewor%204%20-%20CodeCamp%202010.rar"&gt;Source y PPT&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7604231" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="Entity Framework" scheme="http://weblogs.asp.net/marianos/archive/tags/Entity+Framework/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/marianos/archive/tags/C_2300_/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/marianos/archive/tags/.NET/default.aspx" /></entry><entry><title>Me at the 'Level Extreme' .NET online magazine</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2008/02/14/me-at-the-level-extreme-net-online-magazine.aspx" /><id>http://weblogs.asp.net/marianos/archive/2008/02/14/me-at-the-level-extreme-net-online-magazine.aspx</id><published>2008-02-14T18:46:01Z</published><updated>2008-02-14T18:46:01Z</updated><content type="html">&lt;p&gt;I wrote an &lt;a href="http://www.levelextreme.net/ViewPageArticle.aspx?Session=57477A4E324858746D436F3D2077444554557149522B46306A436D6A63745A334746413D3D"&gt;article&lt;/a&gt; about &lt;a href="http://msdn2.microsoft.com/en-us/netframework/aa663328.aspx"&gt;Workflow Foundation&lt;/a&gt; Custom Activities for the .NET online magazine &lt;a href="http://www.levelextreme.net/"&gt;'Level Extreme'&lt;/a&gt;.    &lt;br /&gt;I hope you enjoy it!&lt;/p&gt;  &lt;p&gt;Thanks to MVP &lt;a href="http://www.salias.com.ar/"&gt;Mart&amp;#237;n Sal&amp;#237;as&lt;/a&gt; for the opportunity!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5787779" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author></entry><entry><title>Send mails from .NET</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2008/01/09/send-mails-from-net.aspx" /><id>http://weblogs.asp.net/marianos/archive/2008/01/09/send-mails-from-net.aspx</id><published>2008-01-09T14:04:18Z</published><updated>2008-01-09T14:04:18Z</updated><content type="html">&lt;p&gt;.NET offers a simple way to send mails from our applications.   &lt;br /&gt;We only need to create a instance of the class MailMessage, that will represent the email, and another instance of the class Smtp that will act like a Smtp Client to send the email.    &lt;br /&gt;Both of them are on the System.Net.Mail namespace.    &lt;br /&gt;The source code to use is very simple:&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20  \cf3 MailMessage\cf0  mail = \cf4 new\cf0  \cf3 MailMessage\cf0 (emailData.From, emailData.To, emailData.Subject, emailData.Content);\par ??            \cf3 SmtpClient\cf0  client = \cf4 new\cf0  \cf3 SmtpClient\cf0 ();\par ??            client.Send(mail);}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&amp;#160;&lt;span style="color: #2b91af"&gt;MailMessage&lt;/span&gt; mail = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MailMessage&lt;/span&gt;(from, to, subject, content);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#160;&lt;span style="color: #2b91af"&gt;SmtpClient&lt;/span&gt; client = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SmtpClient&lt;/span&gt;();&lt;/p&gt;    &lt;p style="margin: 0px"&gt; client.Send(mail);&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;And we need to specify the configuration for the Smtp client. You can configure it to use an Exchange server.   &lt;br /&gt;That can be done on the App.Config / Web.Config.&lt;/p&gt;  &lt;p&gt;Here is the configuration:&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 system.net\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 mailSettings\cf1 &amp;gt;\par ??\tab \tab \tab &amp;lt;\cf3 smtp\cf1  \cf4 deliveryMethod\cf1 =\cf0 "\cf1 Network\cf0 "\cf1 &amp;gt;\par ??\tab \tab \tab \tab &amp;lt;\cf3 network\par ??\cf1       \cf4 host\cf1 =\cf0 "\cf1 turing\cf0 "\par ??\cf1       \cf4 port\cf1 =\cf0 "\cf1 25\cf0 "\par ??\cf1       \cf4 userName\cf1 =\cf0 "\cf1 LagashSystems\\marianos\cf0 "\par ??\cf1       \cf4 password\cf1 =\cf0 "\cf1 Password11\cf0 "\cf1 /&amp;gt;\par ??\tab \tab \tab &amp;lt;/\cf3 smtp\cf1 &amp;gt;\par ??\tab \tab &amp;lt;/\cf3 mailSettings\cf1 &amp;gt;\par ??\tab &amp;lt;/\cf3 system.net\cf1 &amp;gt;}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.net&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;       &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mailSettings&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;smtp&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;deliveryMethod&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Network&lt;/span&gt;&amp;quot;&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;network&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;host&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;mailHost&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;port&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;25&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;userName&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Domain\Name&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: red"&gt;password&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Password&lt;/span&gt;&amp;quot;&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;smtp&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;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;mailSettings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;       &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.net&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5575325" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author></entry><entry><title>Creating a Workflow Foundation Custom Activity with Activity Derivation</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2007/11/02/creating-a-workflow-foundation-custom-activity-with-activity-derivation.aspx" /><id>http://weblogs.asp.net/marianos/archive/2007/11/02/creating-a-workflow-foundation-custom-activity-with-activity-derivation.aspx</id><published>2007-11-02T18:09:43Z</published><updated>2007-11-02T18:09:43Z</updated><content type="html">&lt;p&gt;Activity derivation is one of the two methods to create Custom Activities. Unlike the composition (the another method), where with several basic activities we can create a new large and complex activity, on this method we focus on creating one single activity, defining their properties and execution model. Let's look at an example of an activity created by this method, wich will be aiming to display a message on the console. &lt;/p&gt;  &lt;p&gt;To do that we must create a new project of Workflow Activity Library type. We will name it &amp;#x201C;WFActivityDerivation&amp;#x201D;. and add a new class called ActivityDerivationExample.cs, which the following code:&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 class\cf0  \cf4 ActivityDerivationExample\cf0  : Activity\par ??\{\par ??    \cf1 string\cf0  _text;\par ??\par ??    \cf1 public\cf0  \cf1 string\cf0  Text\par ??    \{\par ??        \cf1 get\cf0  \{ \cf1 return\cf0  _text; \}\par ??        \cf1 set\cf0  \{ _text = \cf1 value\cf0 ; \}\par ??    \}\par ??\par ??    \cf1 protected\cf0  \cf1 override\cf0  ActivityExecutionStatus Execute(\par ??    ActivityExecutionContext executionContext)\par ??    \{\par ??        \cf4 Console\cf0 .WriteLine(Text);\par ??        \cf4 Console\cf0 .ReadKey();\par ??        \cf1 return\cf0  ActivityExecutionStatus.Closed;\par ??    \}\par ??\}}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&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;ActivityDerivationExample&lt;/span&gt; : Activity&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;string&lt;/span&gt; _text;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Text&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; _text; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;set&lt;/span&gt; { _text = &lt;span style="color: blue"&gt;value&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; ActivityExecutionStatus Execute(&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; ActivityExecutionContext executionContext)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(Text);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadKey();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;return&lt;/span&gt; ActivityExecutionStatus.Closed;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The class inherits from System.Workflow.ComponentModel.Activity, which is the base of all activities in WF. Our example activity exposes a property called &amp;#x201C;Text&amp;#x201D; whose value can be set from the workflow designer and which will be displayed on the console when the activity run.&lt;/p&gt;  &lt;p&gt;The main feature of this class is the Execute method. When we override this method we are assuming full responsability for the behavior of the activity. When the time comes to execute our custom activity, WF runtime will invoke our Execute method and then show our message on the console. After that we need to tell the WF runtime that our activity execution has ended, returning the value Closed of the ActivityExecutionStatus.&lt;/p&gt;  &lt;p&gt;At this point we can build our activity and create the assembly for distribution.&lt;/p&gt;  &lt;p&gt;&amp;#xA0;&lt;/p&gt;  &lt;h3&gt;Activity Designers:&lt;/h3&gt;  &lt;p&gt;The Activity Designers are used to control the appearance of the activities at design time. To create a designer we need a new class that inherits from ActivityDesigner and override their virtual methods. The following example shows how to override the method OnPaint, who draws our activity in the designer's workflow:&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 public\cf0  \cf1 class\cf0  \cf4 ActivityDerivationDesigner\cf0  : ActivityDesigner\par ??\{\par ??    \cf4 ActivityDerivationExample\cf0  _activity;\par ??    \cf1 protected\cf0  \cf1 override\cf0  \cf1 void\cf0  Initialize(Activity activity)\par ??    \{\par ??        _activity = activity \cf1 as\cf0  \cf4 ActivityDerivationExample\cf0 ;\par ??        \cf1 base\cf0 .Initialize(activity);\par ??    \}\par ??\par ??    \cf1 protected\cf0  \cf1 override\cf0  \cf1 void\cf0  OnPaint(ActivityDesignerPaintEventArgs e)\par ??    \{\par ??        e.Graphics.FillRectangle(Brushes.Black, Location.X, Location.Y, Size.Width, Size.Height);\par ??        Rectangle rect = \cf1 new\cf0  Rectangle(Location.X, Location.Y, Size.Width, 15);\par ??        Font font = \cf1 new\cf0  Font(\cf5 "Lucida Console"\cf0 , 8);\par ??        e.Graphics.DrawString(\cf5 @"C:\\&amp;gt; "\cf0  + _activity.Text, font, Brushes.White, rect.X, rect.Y + 10);\par ??\par ??    \}\par ??\}}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&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;ActivityDerivationDesigner&lt;/span&gt; : ActivityDesigner&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: #2b91af"&gt;ActivityDerivationExample&lt;/span&gt; _activity;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Initialize(Activity activity)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; _activity = activity &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ActivityDerivationExample&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;base&lt;/span&gt;.Initialize(activity);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; OnPaint(ActivityDesignerPaintEventArgs e)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; e.Graphics.FillRectangle(Brushes.Black, Location.X, Location.Y, Size.Width, Size.Height);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; Rectangle rect = &lt;span style="color: blue"&gt;new&lt;/span&gt; Rectangle(Location.X, Location.Y, Size.Width, 15);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; Font font = &lt;span style="color: blue"&gt;new&lt;/span&gt; Font(&lt;span style="color: #a31515"&gt;&amp;quot;Lucida Console&amp;quot;&lt;/span&gt;, 8);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; e.Graphics.DrawString(&lt;span style="color: #a31515"&gt;@&amp;quot;C:\&amp;gt; &amp;quot;&lt;/span&gt; + _activity.Text, font, Brushes.White, rect.X, rect.Y + 10);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;The following syntax is used to associate the designer to our activity::&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green128\blue0;\red255\green255\blue255;\red0\green0\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf1 //ActivityDerivationExampe.cs\par ??\cf0 [Designer(\cf4 typeof\cf0 (\cf5 ActivityDerivationDesigner\cf0 ))]\par ??\cf4 public\cf0  \cf4 class\cf0  \cf5 ActivityDerivationExample\cf0  : Activity\par ??\{\par ??    \cf1 //\par ??\cf0 \}\par ??}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;//ActivityDerivationExampe.cs&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;[Designer(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ActivityDerivationDesigner&lt;/span&gt;))]&lt;/p&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;ActivityDerivationExample&lt;/span&gt; : Activity&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: green"&gt;//&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;} &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;With this, our activity will looks like the following picture:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/marianos/WindowsLiveWriter/CreatingaWorkflowFoundationCustomActivit_D533/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="76" alt="image" src="http://weblogs.asp.net/blogs/marianos/WindowsLiveWriter/CreatingaWorkflowFoundationCustomActivit_D533/image_thumb_1.png" width="152" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#xA0;&lt;/p&gt;  &lt;h3&gt;Activity Validators:&lt;/h3&gt;  &lt;p&gt;The Activity Validators run at design and build time, and are used to ensure that the activity has the correct settings to run. To create a validator need a new class that inherits from the class ActivityValidator and overwrite method Validate.    &lt;br /&gt;For example the following validator will ensure that our activity has a valid value in the Text property:&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 class\cf0  \cf4 ActivityDerivationValidator\cf0  : ActivityValidator\par ??\{\par ??    \cf1 public\cf0  \cf1 override\cf0  ValidationErrorCollection Validate(ValidationManager manager, \cf1 object\cf0  obj)\par ??    \{\par ??        ValidationErrorCollection errors = \cf1 base\cf0 .Validate(manager, obj);\par ??        \cf4 ActivityDerivationExample\cf0  activity = obj \cf1 as\cf0  \cf4 ActivityDerivationExample\cf0 ;\par ??        \cf1 if\cf0  (activity.Parent != \cf1 null\cf0  &amp;amp;&amp;amp; \cf4 String\cf0 .IsNullOrEmpty(activity.Text))\par ??        \{\par ??            errors.Add(ValidationError.GetNotSetValidationError(\cf5 "Text"\cf0 ));\par ??        \}\par ??        \cf1 return\cf0  errors;\par ??    \}\par ??\}}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ActivityDerivationValidator&lt;/span&gt; : ActivityValidator&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; ValidationErrorCollection Validate(ValidationManager manager, &lt;span style="color: blue"&gt;object&lt;/span&gt; obj)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; ValidationErrorCollection errors = &lt;span style="color: blue"&gt;base&lt;/span&gt;.Validate(manager, obj);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: #2b91af"&gt;ActivityDerivationExample&lt;/span&gt; activity = obj &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ActivityDerivationExample&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;if&lt;/span&gt; (activity.Parent != &lt;span style="color: blue"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.IsNullOrEmpty(activity.Text))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; errors.Add(ValidationError.GetNotSetValidationError(&lt;span style="color: #a31515"&gt;&amp;quot;Text&amp;quot;&lt;/span&gt;));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;return&lt;/span&gt; errors;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;All validation errors are added to the ValidationErrorCollection collection and returned to the caller.&lt;/p&gt;  &lt;p&gt;The following syntax is used to associate the validator to our activity:&amp;#xA0; &lt;br /&gt;&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green128\blue0;\red255\green255\blue255;\red0\green0\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf1 //ActivityDerivationExampe.cs\par ??\cf0 [ActivityValidator(\cf4 typeof\cf0 (\cf5 ActivityDerivationValidator\cf0 ))]\par ??\cf4 public\cf0  \cf4 class\cf0  \cf5 ActivityDerivationExample\cf0  : Activity\par ??\{\par ??    \cf1 //\par ??\cf0 \}\par ??}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;//ActivityDerivationExampe.cs&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;[ActivityValidator(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ActivityDerivationValidator&lt;/span&gt;))]&lt;/p&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;ActivityDerivationExample&lt;/span&gt; : Activity&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: green"&gt;//&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;h4&gt;&lt;/h4&gt; &lt;/div&gt;  &lt;h3&gt;Conclusion:&lt;/h3&gt;  &lt;p&gt;The Activity Derivation allow us to create new activities that inherits from the base class Activity. You can also inherits from other classes that implement Activity, to use more features. This method gives us the highest level of control and offers us a way to extend WF code itself.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4866470" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="WF" scheme="http://weblogs.asp.net/marianos/archive/tags/WF/default.aspx" /></entry><entry><title>Certificate Access Error in a IIS hosted WCF Service</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2007/11/01/certificate-access-error-in-a-iis-hosted-wcf-service.aspx" /><id>http://weblogs.asp.net/marianos/archive/2007/11/01/certificate-access-error-in-a-iis-hosted-wcf-service.aspx</id><published>2007-11-01T19:15:22Z</published><updated>2007-11-01T19:15:22Z</updated><content type="html">&lt;p&gt;The problem appears when a WCF Service hosted in an IIS tries to load a certificate from the Windows Certificates Store with the account of the Application Pool where the service runs, and the account&amp;#x2019;s profile is not previously loaded. When a user logs on interactively, the system automatically loads the user's profile. If a service or an application impersonates a user, the system does not load the user's profile. Therefore, the service or application should load the user's profile with &lt;i&gt;LoadUserProfile&lt;/i&gt;.&lt;/p&gt;  &lt;p&gt;When this happens the operation throws the following exception: &lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;System.Security.Cryptography.CryptographicException: The system cannot find the file specified.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;See &lt;a href="http://support.microsoft.com/kb/939761"&gt;http://support.microsoft.com/kb/939761&lt;/a&gt; Microsoft Knowledge Base Article for detailed information.&lt;/p&gt;  &lt;p&gt;A workaround to this problem is to load the Application Pool Identity Account&amp;#xB4;s profile before the service call is executed. Placing the code in the &lt;i&gt;Application_Start&lt;/i&gt;() method on the &lt;i&gt;Global.asax&lt;/i&gt; of the IIS host will solve the problem (see &lt;a href="http://msdn2.microsoft.com/en-us/library/aa374341.aspx"&gt;http://msdn2.microsoft.com/en-us/library/aa374341.aspx&lt;/a&gt; for detailed information).&lt;/p&gt;  &lt;p&gt;Here is the code:&lt;/p&gt; &lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf1 private\cf0  ProfileManager.PROFILEINFO profile;\par ??\par ??\cf1 protected\cf0  \cf1 void\cf0  Application_Start(\cf1 object\cf0  sender, EventArgs e)\par ??\{\par ??    \cf1 bool\cf0  retVal = \cf1 false\cf0 ;\par ??    \cf4 // Need to duplicate the token. LoadUserProfile needs a token with \par ??\cf0     \cf4 // TOKEN_IMPERSONATE and TOKEN_DUPLICATE.\par ??\cf0     \cf1 const\cf0  \cf1 int\cf0  SecurityImpersonation = 2;\par ??    dupeTokenHandle = DupeToken(WindowsIdentity.GetCurrent().Token, SecurityImpersonation);\par ??    \par ??    \cf1 if\cf0  (IntPtr.Zero == dupeTokenHandle)\par ??    \{\par ??        \cf1 throw\cf0  \cf1 new\cf0  Exception(\cf5 "Unable to duplicate token."\cf0 );\par ??    \}\par ??\par ??    \cf4 // Load the profile.\par ??\cf0     profile = \cf1 new\cf0  ProfileManager.PROFILEINFO();\par ??    profile.dwSize = 32;\par ??    \cf4 //Domain\\User\par ??\cf0     profile.lpUserName = \cf5 @"MyDomain\\UserName"\cf0 ; \par ??    retVal = ProfileManager.LoadUserProfile(dupeTokenHandle, \cf1 ref\cf0  profile);\par ??\par ??    \cf1 if\cf0  (!retVal)\par ??    \{\par ??        \cf1 throw\cf0  \cf1 new\cf0  Exception(\cf5 "Error loading user profile. "\cf0  + Marshal.GetLastWin32Error());\par ??    \}\par ??\}\par ??\par ??\cf1 protected\cf0  \cf1 void\cf0  Application_End(\cf1 object\cf0  sender, EventArgs e)\par ??\{\par ??    ProfileManager.UnloadUserProfile(WindowsIdentity.GetCurrent().Token, profile.hProfile);\par ??    CloseHandle(dupeTokenHandle);\par ??\}\par ??\par ??\cf1 private\cf0  IntPtr DupeToken(IntPtr token, \cf1 int\cf0  Level)\par ??\{\par ??    IntPtr dupeTokenHandle = \cf1 new\cf0  IntPtr(0);\par ??    \cf1 bool\cf0  retVal = DuplicateToken(token, Level, \cf1 ref\cf0  dupeTokenHandle);\par ??    \cf1 if\cf0  (\cf1 false\cf0  == retVal)\par ??    \{\par ??        \cf1 return\cf0  IntPtr.Zero;\par ??    \}\par ??    \cf1 return\cf0  dupeTokenHandle;\par ??\}\par ??\par ??\cf1 internal\cf0  \cf1 class\cf0  ProfileManager\par ??\{\par ??    [DllImport(\cf5 "Userenv.dll"\cf0 , SetLastError = \cf1 true\cf0 , CharSet = System.Runtime.InteropServices.CharSet.Auto)]\par ??    \cf1 internal\cf0  \cf1 static\cf0  \cf1 extern\cf0  \cf1 bool\cf0  LoadUserProfile(IntPtr hToken, \cf1 ref\cf0  PROFILEINFO lpProfileInfo);\par ??    [DllImport(\cf5 "Userenv.dll"\cf0 , SetLastError = \cf1 true\cf0 , CharSet = System.Runtime.InteropServices.CharSet.Auto)]\par ??    \cf1 internal\cf0  \cf1 static\cf0  \cf1 extern\cf0  \cf1 bool\cf0  UnloadUserProfile(IntPtr hToken, IntPtr hProfile);\par ??\par ??    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]\par ??    \cf1 public\cf0  \cf1 struct\cf0  PROFILEINFO\par ??    \{\par ??        \cf1 public\cf0  \cf1 int\cf0  dwSize;\par ??        \cf1 public\cf0  \cf1 int\cf0  dwFlags;\par ??        \cf1 public\cf0  String lpUserName;\par ??        \cf1 public\cf0  String lpProfilePath;\par ??        \cf1 public\cf0  String lpDefaultPath;\par ??        \cf1 public\cf0  String lpServerName;\par ??        \cf1 public\cf0  String lpPolicyPath;\par ??        \cf1 public\cf0  IntPtr hProfile;\par ??    \}\par ??\}}
--&gt;  &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;private&lt;/span&gt; ProfileManager.PROFILEINFO profile;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Application_Start(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;bool&lt;/span&gt; retVal = &lt;span style="color: blue"&gt;false&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: green"&gt;// Need to duplicate the token. LoadUserProfile needs a token with &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: green"&gt;// TOKEN_IMPERSONATE and TOKEN_DUPLICATE.&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;const&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; SecurityImpersonation = 2;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; dupeTokenHandle = DupeToken(WindowsIdentity.GetCurrent().Token, SecurityImpersonation);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;if&lt;/span&gt; (IntPtr.Zero == dupeTokenHandle)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;throw&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #a31515"&gt;&amp;quot;Unable to duplicate token.&amp;quot;&lt;/span&gt;);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: green"&gt;// Load the profile.&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; profile = &lt;span style="color: blue"&gt;new&lt;/span&gt; ProfileManager.PROFILEINFO();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; profile.dwSize = 32;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: green"&gt;//Domain\User&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; profile.lpUserName = &lt;span style="color: #a31515"&gt;@&amp;quot;MyDomain\UserName&amp;quot;&lt;/span&gt;; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; retVal = ProfileManager.LoadUserProfile(dupeTokenHandle, &lt;span style="color: blue"&gt;ref&lt;/span&gt; profile);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!retVal)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;throw&lt;/span&gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #a31515"&gt;&amp;quot;Error loading user profile. &amp;quot;&lt;/span&gt; + Marshal.GetLastWin32Error());&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Application_End(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; ProfileManager.UnloadUserProfile(WindowsIdentity.GetCurrent().Token, profile.hProfile);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; CloseHandle(dupeTokenHandle);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;private&lt;/span&gt; IntPtr DupeToken(IntPtr token, &lt;span style="color: blue"&gt;int&lt;/span&gt; Level)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; IntPtr dupeTokenHandle = &lt;span style="color: blue"&gt;new&lt;/span&gt; IntPtr(0);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;bool&lt;/span&gt; retVal = DuplicateToken(token, Level, &lt;span style="color: blue"&gt;ref&lt;/span&gt; dupeTokenHandle);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;if&lt;/span&gt; (&lt;span style="color: blue"&gt;false&lt;/span&gt; == retVal)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;return&lt;/span&gt; IntPtr.Zero;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;return&lt;/span&gt; dupeTokenHandle;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;internal&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; ProfileManager&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; [DllImport(&lt;span style="color: #a31515"&gt;&amp;quot;Userenv.dll&amp;quot;&lt;/span&gt;, SetLastError = &lt;span style="color: blue"&gt;true&lt;/span&gt;, CharSet = System.Runtime.InteropServices.CharSet.Auto)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;internal&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;extern&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; LoadUserProfile(IntPtr hToken, &lt;span style="color: blue"&gt;ref&lt;/span&gt; PROFILEINFO lpProfileInfo);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; [DllImport(&lt;span style="color: #a31515"&gt;&amp;quot;Userenv.dll&amp;quot;&lt;/span&gt;, SetLastError = &lt;span style="color: blue"&gt;true&lt;/span&gt;, CharSet = System.Runtime.InteropServices.CharSet.Auto)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;internal&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;extern&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; UnloadUserProfile(IntPtr hToken, IntPtr hProfile);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;struct&lt;/span&gt; PROFILEINFO&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; dwSize;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; dwFlags;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; String lpUserName;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; String lpProfilePath;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; String lpDefaultPath;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; String lpServerName;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; String lpPolicyPath;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0;&amp;#xA0; &lt;span style="color: blue"&gt;public&lt;/span&gt; IntPtr hProfile;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&amp;#xA0;&amp;#xA0;&amp;#xA0; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;An alternative workaround consists in creating a Windows Service account that loads at system start-up using the Application Pool Service Identity.&lt;/p&gt;  &lt;p&gt;Thanks to JavierA for helping me to find the solution.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4855954" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author><category term="WCF" scheme="http://weblogs.asp.net/marianos/archive/tags/WCF/default.aspx" /><category term="Security" scheme="http://weblogs.asp.net/marianos/archive/tags/Security/default.aspx" /></entry><entry><title>The beginning</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/marianos/archive/2007/11/01/the-beginning.aspx" /><id>http://weblogs.asp.net/marianos/archive/2007/11/01/the-beginning.aspx</id><published>2007-11-01T19:14:30Z</published><updated>2007-11-01T19:14:30Z</updated><content type="html">&lt;p&gt;Hi, my name is Mariano, I'm from Argentina and I&amp;#xB4;m 25.    &lt;br /&gt;I have programmed computers since I was 15 and I really enjoy it.     &lt;br /&gt;I'm in the computer business since year 2000 and now I'm working as developer for Lagash Systems S.A. mainly with Microsoft technology.&lt;/p&gt;  &lt;p&gt;This is my first blog, so I hope you find it interesting!! (I will try to keep it updated!!)&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4855950" width="1" height="1"&gt;</content><author><name>MarianoS</name><uri>http://weblogs.asp.net/members/MarianoS.aspx</uri></author></entry></feed>