<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Glopez Blog</title>
	
	<link>http://www.glopez.es</link>
	<description />
	<lastBuildDate>Sun, 16 May 2010 14:02:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/GlopezBlog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="glopezblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>URL amigables con wordpress en IIS</title>
		<link>http://www.glopez.es/wordpress/url-amigables-con-wordpress-en-iis/</link>
		<comments>http://www.glopez.es/wordpress/url-amigables-con-wordpress-en-iis/#comments</comments>
		<pubDate>Sun, 16 May 2010 14:01:14 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[IIS]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=257</guid>
		<description><![CDATA[Por defecto wordpress genera unas url para nuestros post un poco cripticas, utilizando el identificador del post, pero como sabemos, esto no es de utilidad ni para el usuario, ni sobre todo para los buscadores. WordPress tiene un apartado (Opciones -&#62; Enlaces permanentes) dónde se nos permite configurar este comportamiento, pero si estamos alojados en [...]]]></description>
			<content:encoded><![CDATA[<p>Por defecto wordpress genera unas url para nuestros post un poco cripticas, utilizando el identificador del post, pero como sabemos, esto no es de utilidad ni para el usuario, ni sobre todo para los buscadores. WordPress tiene un apartado (<em><strong>Opciones -&gt; Enlaces permanentes</strong></em>) dónde se nos permite configurar este comportamiento, pero si estamos alojados en un servidor con IIS (<em>Internet Information Services</em>) y modificamos la opción por defecto, obtendremos errores 404 al navegar por nuestra web.</p>
<p>Yo hace unas semanas que lo cambié y he notado una mejora considerable en cuanto a visitas se refiere – sin haber mejorado en nada el contenido :p – Así que quiero explicar cómo solucionar esto porque considero que es recomendable hacerlo.</p>
<p>Los requisitos serán:</p>
<ul>
<li>IIS 7 con FastCGI y PHP instalado</li>
<li>Un wordpress <img src='http://www.glopez.es/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>El modulo URL rewrite Go live de IIS instalado.</li>
</ul>
<p>Primero nos vamos a la administración del blog y cambiamos las opciones de enlaces permanentes como se muestra en la imagen.</p>
<p><img src="http://www.glopez.es/wp-content/uploads/2010/05/Captura.png" alt="" title="Enlaces permanentes" width="635" height="560" class="aligncenter size-full wp-image-258" /></p>
<p>* <em>NOTA</em>: yo he utilizado una combinación de categoría y nombre del post, en el siguiente <a href="http://codex.wordpress.org/Using_Permalinks">enlace</a> encontrareis más información sobre qué datos podéis configurar en vuestras URLs.</p>
<p>Ahora tenemos que ir al fichero <strong>web.config</strong> del servidor dónde tenemos nuestro wordpress y editarlo añadiendo dentro del elemento <em>system.webServer</em> la configuración:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Main Rule&quot;</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;.*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;conditions</span> <span style="color: #000066;">logicalGrouping</span>=<span style="color: #ff0000;">&quot;MatchAll&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsFile&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;{REQUEST_FILENAME}&quot;</span> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">&quot;IsDirectory&quot;</span> <span style="color: #000066;">negate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/conditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Rewrite&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;index.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rewrite<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Ya lo tenemos preparado, ahora podemos navegar con las url personalizadas y posiblemente nuestras visitas mejoren <img src='http://www.glopez.es/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/wordpress/url-amigables-con-wordpress-en-iis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calculando el tamaño de tu base de datos SQL Azure</title>
		<link>http://www.glopez.es/sql-azure/calculando-el-tamano-de-tu-base-de-datos-sql-azure/</link>
		<comments>http://www.glopez.es/sql-azure/calculando-el-tamano-de-tu-base-de-datos-sql-azure/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 20:38:39 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[SQL Azure]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=251</guid>
		<description><![CDATA[Recojo dos sentencias que pueden ser muy útiles para conocer el tamaño total de nuestra base de datos SQL Azure (primera sentencia) y el tamaño de todas sus tablas (segunda sentencia): &#160; select CONVERT&#40;DECIMAL&#40;5,2&#41;, ROUND&#40;sum&#40;reserved_page_count&#41; * 8.0 / 1024, 2&#41;&#41; from sys.dm_db_partition_stats &#160; GO &#160; select sys.objects.name, CONVERT&#40;DECIMAL&#40;5,2&#41;, ROUND&#40;sum&#40;reserved_page_count&#41; * 8.0 / 1024, 2&#41;&#41; AS [...]]]></description>
			<content:encoded><![CDATA[<p>Recojo dos sentencias que pueden ser muy útiles para conocer el tamaño total de nuestra base de datos SQL Azure (primera sentencia) y el tamaño de todas sus tablas (segunda sentencia):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">&nbsp;
select CONVERT<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">DECIMAL</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span>,<span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>, ROUND<span style="color: #000000;">&#40;</span>sum<span style="color: #000000;">&#40;</span>reserved_page_count<span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">8.0</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">1024</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
from sys.<span style="color: #0000FF;">dm_db_partition_stats</span>
&nbsp;
GO
&nbsp;
select sys.<span style="color: #0000FF;">objects</span>.<span style="color: #0000FF;">name</span>, CONVERT<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">DECIMAL</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span>,<span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>,
ROUND<span style="color: #000000;">&#40;</span>sum<span style="color: #000000;">&#40;</span>reserved_page_count<span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">8.0</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">1024</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">AS</span> TAMAÑO
from sys.<span style="color: #0000FF;">dm_db_partition_stats</span>, sys.<span style="color: #0000FF;">objects</span> 
where sys.<span style="color: #0000FF;">dm_db_partition_stats</span>.<span style="color: #0000FF;">object_id</span> <span style="color: #008000;">=</span> sys.<span style="color: #0000FF;">objects</span>.<span style="color: #0000FF;">object_id</span>
group by sys.<span style="color: #0000FF;">objects</span>.<span style="color: #0000FF;">name</span>
ORDER BY TAMAÑO DESC</pre></div></div>

<p>Los datos se presentan en <strong>MB</strong>.</p>
<p>vía blog de <a href="http://dunnry.com/blog/CalculatingTheSizeOfYourSQLAzureDatabase.aspx">Ryan Dunn</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/sql-azure/calculando-el-tamano-de-tu-base-de-datos-sql-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conocer las propiedades de una clase con reflection</title>
		<link>http://www.glopez.es/c/conocer-las-propiedades-de-una-clase-con-reflection/</link>
		<comments>http://www.glopez.es/c/conocer-las-propiedades-de-una-clase-con-reflection/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 23:06:02 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=246</guid>
		<description><![CDATA[A veces nos puede ser interesante conocer que propiedades tiene una clase, vamos a ver cómo realizar esto con ayuda de la reflexión. Utilizaremos el namespace using System.Reflection; Lo primero de todo es crear una nueva instancia de la clase que queremos analizar, y utilizando el método GetType() heredado de la clase object, accederemos al [...]]]></description>
			<content:encoded><![CDATA[<p>A veces nos puede ser interesante conocer que propiedades tiene una clase, vamos a ver cómo realizar esto con ayuda de la reflexión.<br />
Utilizaremos el namespace <span style="color: #0000ff;">using </span>System.Reflection;</p>
<p>Lo primero de todo es  crear una nueva instancia de la clase que queremos analizar, y utilizando el método <em>GetType</em>() heredado de la clase <span style="color: #0000ff;">object</span>, accederemos al método <em>GetProperties</em>()<br />
Esto nos devuelve un array de tipo <em>PropertyInfo</em>, que podemos recorrer con un <em>foreach </em>y conocer así las propiedades de la propiedad <img src='http://www.glopez.es/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Persona
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Edad <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Nombre <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Persona p <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Persona<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        PropertyInfo<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> propiedades <span style="color: #008000;">=</span> p.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetProperties</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>PropertyInfo propiedad <span style="color: #0600FF;">in</span> propiedades<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>propiedad.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; : &quot;</span> <span style="color: #008000;">+</span> propiedad.<span style="color: #0000FF;">PropertyType</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Done&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        Console.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>También podemos recuperar y asignar valores utilizando:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    Persona p <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Persona<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    p.<span style="color: #0000FF;">Edad</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">18</span><span style="color: #008000;">;</span>
    PropertyInfo<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> propiedades <span style="color: #008000;">=</span> p.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetProperties</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>PropertyInfo propiedad <span style="color: #0600FF;">in</span> propiedades<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>propiedad.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Edad&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Edad: &quot;</span> <span style="color: #008000;">+</span> propiedad.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span>p, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>propiedad.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Nombre&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            propiedad.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span>p, <span style="color: #666666;">&quot;Pepe&quot;</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Nombre: &quot;</span> <span style="color: #008000;">+</span> propiedad.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span>p, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Done&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Console.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/c/conocer-las-propiedades-de-una-clase-con-reflection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problema con entity framework y Sql Azure</title>
		<link>http://www.glopez.es/sql-azure/problema-con-entity-framework-y-sql-azure/</link>
		<comments>http://www.glopez.es/sql-azure/problema-con-entity-framework-y-sql-azure/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 17:29:46 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[Entity framework]]></category>
		<category><![CDATA[SQL Azure]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=238</guid>
		<description><![CDATA[EDIT: Desde el 9 de Abril de 2010 SQL Azure tiene soporte para MARS, asi que deja de existir este problema. http://blogs.msdn.com/sqlazure/default.aspx Probando Entity Framework 4.0 en un desarrollo con SQL Azure me he encontrado un problema con la conexión. Si creas el Entity Data Model generado desde una base de datos local con el [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: #ff0000;">EDIT:</span></strong> Desde el 9 de Abril de 2010 SQL Azure tiene soporte para MARS, asi que deja de existir este problema. <a href="http://blogs.msdn.com/sqlazure/default.aspx">http://blogs.msdn.com/sqlazure/default.aspx</a></p>
<p>Probando <strong>Entity Framework 4.0</strong> en un desarrollo con <strong>SQL Azure</strong> me he encontrado un problema con la conexión. Si creas el <em>Entity Data Model</em> generado desde una base de datos local con el <em>Wizard </em>de Visual Studio, por defecto asigna una cadena de conexión de este estilo:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">connectionString=&quot;metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=DataBaseServer;Initial Catalog=DataBaseName;Integrated Security=True;MultipleActiveResultSets=True&quot;&quot; providerName=&quot;System.Data.EntityClient&quot;</pre></div></div>

<p>Si una vez que hayamos hecho nuestras pruebas, queremos apuntar la cadena de conexión a nuestra BD en SQL Azure, tenemos que indicarle al atributo <strong>MultipleActiveResultSets=False</strong>, ya que no está soportado en SQL Azure y si no lo deshabilitamos, nos fallará cada intento de conexión.</p>
<p>La cadena de conexión debería quedar así:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">connectionString=&quot;metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxxxxxxxxx.database.windows.net;Initial Catalog=DataBaseName;Persist Security Info=True;User ID=UserID;Password=Password;MultipleActiveResultSets=False&quot;&quot; providerName=&quot;System.Data.EntityClient&quot;</pre></div></div>

<p>* Si desde el Wizard de creación del <em>Entity Data Model</em> ya seleccionamos una conexión de SQL Azure, por defecto deja este parámetro en False.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/sql-azure/problema-con-entity-framework-y-sql-azure/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silverlight: Error 1 Length cannot be less than zero.Parameter name: length</title>
		<link>http://www.glopez.es/silverlight/silverlight-error-1-length-cannot-be-less-than-zero-parameter-name-length/</link>
		<comments>http://www.glopez.es/silverlight/silverlight-error-1-length-cannot-be-less-than-zero-parameter-name-length/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 01:44:03 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=229</guid>
		<description><![CDATA[Desarrollando con silverlight me he encontrado con este error: Error 1 Length cannot be less than zero. Parameter name: length. Quiero compartir la solución por lo poco intuitivo que resulta el mensaje para localizar el error en nuestro código. Entorno dónde reproducir el error: Visual Studio 2010 RC, proyecto de Silverlight 4 RC. Este error [...]]]></description>
			<content:encoded><![CDATA[<p>Desarrollando con <strong>silverlight</strong> me he encontrado con este error: <strong><em>Error 1 Length cannot be less than zero. Parameter name: length</em></strong>. Quiero compartir la solución por lo poco intuitivo que resulta el mensaje para localizar el error en nuestro código.</p>
<p>Entorno dónde reproducir el error: <span style="text-decoration: underline;">Visual Studio 2010 RC</span>, proyecto de <span style="text-decoration: underline;">Silverlight 4 RC</span>.</p>
<p>Este error aparece si al añadir un espacio de nombres a nuestro código XAML lo hacemos con un punto en su prefijo o alias.</p>
<p>Por ejemplo, el siguiente código nos devolvería el error:</p>

<div class="wp_syntax"><div class="code"><pre class="xaml" style="font-family:monospace;">xmlns:Blacklight.Controls=&quot;clr-namespace:Blacklight.Controls;assembly=Blacklight.Controls&quot;</pre></div></div>

<p>Y está sería una manera correcta:</p>

<div class="wp_syntax"><div class="code"><pre class="xaml" style="font-family:monospace;">xmlns:Blacklight_Controls=&quot;clr-namespace:Blacklight.Controls;assembly=Blacklight.Controls&quot;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/silverlight/silverlight-error-1-length-cannot-be-less-than-zero-parameter-name-length/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ordenar elementos con jQuery</title>
		<link>http://www.glopez.es/jquery/ordenar-elementos-con-jquery/</link>
		<comments>http://www.glopez.es/jquery/ordenar-elementos-con-jquery/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 23:50:04 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=200</guid>
		<description><![CDATA[Vamos con otro tema que tenía en cartera hace ya tiempo – debería escribir las cosas cuando las aprendo, y no meses después, que me cuesta el doble &#8211; tuve que hacer algunas pruebas con jQuery que quiero compartir. Necesitaba conseguir un prototipo de interfaz de widgets, estilo iGoogle o netvibes. Para conseguir este efecto, [...]]]></description>
			<content:encoded><![CDATA[<p>Vamos con otro tema que tenía en cartera hace ya tiempo – debería escribir las cosas cuando las aprendo, y no meses después, que me cuesta el doble &#8211; tuve que hacer algunas pruebas con jQuery que quiero compartir. Necesitaba conseguir un prototipo de interfaz de widgets, estilo <a href="http://www.google.es/ig">iGoogle</a> o <a href="http://www.netvibes.com">netvibes</a>.</p>
<div class="aligncenter" style="margin-left: 20px;">
<div style="float: left;">
<a href="http://demo.glopez.es/Default.aspx"><img src="http://www.glopez.es/wp-content/uploads/2010/03/ver.png" alt="ver" title="ver" width="175" height="90" class="size-full wp-image-201" /></a>
</div>
<div style="float: rigth;">
<a href="http://www.glopez.es/wp-content/uploads/2010/03/jQuerySortable.rar"><img src="http://www.glopez.es/wp-content/uploads/2010/03/descargar.png" alt="descargar" title="descargar" width="175" height="90" class="size-full wp-image-202" /></a>
</div>
</div>
<p>Para conseguir este efecto, utilizaremos la función <a href="http://docs.jquery.com/UI/Sortable"><em>sortable</em></a> de <strong>jQuery UI</strong>. Bien, organizamos el html con tres contenedores que harán de columnas y que ha su vez contendran listas para organizar los widgets, mejor ver el código:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrapper&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;uno&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colum&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    Contenido del widget
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'dos'</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colum&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://a1.twimg.com/profile_images/186917016/img2.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;yngir&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'tres'</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colum&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'header'</span>&gt;</span>
                        Drag me
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Configuramos los estilos:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
        div<span style="color: #cc00cc;">#wrapper</span>
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1024px</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        div<span style="color: #6666ff;">.colum</span>
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">33</span>%</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        ul
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        li
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span> <span style="color: #933;">1px</span> Black<span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        <span style="color: #6666ff;">.sortHelper</span>
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        div<span style="color: #cc00cc;">#uno</span> li
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> ActiveBorder<span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        div<span style="color: #cc00cc;">#dos</span> li
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> Highlight<span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        div<span style="color: #cc00cc;">#tres</span> li
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> Yellow<span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        div<span style="color: #6666ff;">.header</span>
        <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> White<span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span> <span style="color: #933;">1px</span> Black<span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">25px</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> move<span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
    &lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>Hasta aquí, deberíamos ver la página cómo la de demo pero sin el movimiento de <em>drag&#038;drop</em>.<br />
Ahora cargamos las librerías necesarias de javascript, que para este caso serán, la <em>jquery.min.js, ui.core.js</em> y <em>ui.sortable.js</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/scripts/ui.core.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/scripts/ui.sortable.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Y por último y más importante, incluimos la función jQuery al final de nuestro html, para que se ejecute una vez ha finalizado la carga de nuestra estructura dom de la página:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
        $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                connectWith<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #339933;">,</span>
                items<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;li&quot;</span><span style="color: #339933;">,</span>
                hoverClass<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;sortHelper&quot;</span><span style="color: #339933;">,</span>
                cursor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'move'</span><span style="color: #339933;">,</span>
                opacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">0.8</span><span style="color: #339933;">,</span>
                revert<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                tolerance<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pointer'</span><span style="color: #339933;">,</span>
                placeholder<span style="color: #339933;">:</span> <span style="color: #3366CC;">'sortHelper'</span><span style="color: #339933;">,</span>
                handle<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.header&quot;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Los parámetros más importantes són el <em>handle </em>que indica desde que elementos se podrá iniciar la acción de ordenación, el <em>items</em>, que indica que elementos serán ordenados y el <em>connectWith</em>, que es el que indica que otros elementos podrán recibir a los items.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/jquery/ordenar-elementos-con-jquery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Servicio para localización por IP</title>
		<link>http://www.glopez.es/net/servicio-para-localizacion-por-ip/</link>
		<comments>http://www.glopez.es/net/servicio-para-localizacion-por-ip/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 22:09:50 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=195</guid>
		<description><![CDATA[Este tema lo tengo pendiente hace ya unos meses, y por fin puedo hacer el post que tenía pensado, así que vamos a ello. Intentaremos explicar cómo realizar nuestro propio servicio para tener la localización de nuestros visitantes a través de su dirección IP, lo cual puede ser muy interesante para filtrar contenidos, mostrar diferentes [...]]]></description>
			<content:encoded><![CDATA[<p>Este tema lo tengo pendiente hace ya unos meses, y por fin puedo hacer el post que tenía pensado, así que vamos a ello. Intentaremos explicar cómo realizar nuestro propio servicio para tener la localización de nuestros visitantes a través de su dirección IP, lo cual puede ser muy interesante para filtrar contenidos, mostrar diferentes publicidades, etc…</p>
<p>Para realizar esta tarea, lo que se necesita es una Base de datos actualizada con todas las direcciones IP y su localización, existen varias opciones de pago, pero para este caso vamos a utilizar la versión gratuita <a href="http://www.maxmind.com/app/geolitecountry"><em>GeoLite Country</em></a> de <strong>MaxMind</strong> que proporciona un acierto del 99.5% &#8211; lo cual es suficiente en la mayoría de los casos – y además, la actualizan cada mes debido a que los <em>ISP</em> van variando la localización de las direcciones IP.</p>
<p>* También existe <a href="http://www.maxmind.com/app/geolitecity"><em>GeoLite City</em></a>, pero después de probarla, obtuve unos resultados malos con su nivel de acierto. Si decidís utilizarla, cuidado con el <em>script</em>, porque pesa un “poquito”,  paciencia cuando importéis los datos – casi 4 millones de registros &#8211; el portátil no fue capaz de ejecutar la consulta, me tiraba un error y tuve que hacerlo desde el PC (¿por fin sirvió para algo el <em>Quad-Core</em>?).</p>
<p>Si no necesitáis aplicar lógica según la localización desde vuestro código servidor, hay varias soluciones vía <em>javascript</em>, yo destacaría la opción del <em>API AJAX</em> de <strong>Google</strong> con el uso de su propiedad <a href="http://code.google.com/intl/es-ES/apis/ajax/documentation/#ClientLocation">google.loader.ClientLocation</a>.</p>
<p>Bien, para nuestro desarrollo utilizaremos las tecnologías <em>LINQ </em>para el sencillo acceso a datos y <em>WCF</em> para nuestro servicio. No voy a entrar en detalles sobre esto, ya existen muy buenos recursos para introducirse en estas tecnologías.</p>
<p>Creamos un nuevo proyecto de <em>Aplicación de servicios WCF</em> en Visual Studio, yo he cambiado el nombre del <strong>ServiceContract </strong>por <em>IGeoIp </em>y he definido dos métodos, uno dónde devolveremos el nombre del país del usuario y el otro dónde devolveremos toda la información:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>ServiceContract<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IGeoIp
<span style="color: #000000;">&#123;</span>
     <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
     <span style="color: #FF0000;">string</span> GetCountryByIp<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> ip<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #000000;">&#91;</span>OperationContract<span style="color: #000000;">&#93;</span>
     WcfServiceGeoIp.<span style="color: #0000FF;">LocalizacionIp</span> GetInfoByIp<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> ip<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>El <strong>DataContract </strong>lo he sacado a un segundo fichero, en este caso <em>InfoIP.cs</em> y le he definido los dos unicos valores que vamos a devolver al cliente, el código <a href="http://es.wikipedia.org/wiki/ISO_3166-1"><em>ISO 3166-1</em></a> del país y su nombre:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>DataContract<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LocalizacionIp
<span style="color: #000000;">&#123;</span>
     <span style="color: #000000;">&#91;</span>DataMember<span style="color: #000000;">&#93;</span>
     <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> CountryCode <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #000000;">&#91;</span>DataMember<span style="color: #000000;">&#93;</span>
     <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Country <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Después implementamos el servicio, que es muy sencillo, simplemente haremos una consulta a la base de datos pasando la dirección en formato <em>double</em>, para lo que nos apoyaremos en el método <em>GetDoubleIp</em>. El servicio quedará así:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ServiceGeoIp <span style="color: #008000;">:</span> IGeoIp
<span style="color: #000000;">&#123;</span>
        <span style="color: #008080;">#region Miembros de IGeoIp</span>
&nbsp;
        <span style="color: #FF0000;">string</span> IGeoIp.<span style="color: #0000FF;">GetCountryByIp</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> ip<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">double</span> dIp <span style="color: #008000;">=</span> GetDoubleIp<span style="color: #000000;">&#40;</span>ip<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> WcfServiceGeoIp.<span style="color: #0000FF;">Facade</span>.<span style="color: #0000FF;">GetCountryByIp</span><span style="color: #000000;">&#40;</span>dIp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        WcfServiceGeoIp.<span style="color: #0000FF;">LocalizacionIp</span> IGeoIp.<span style="color: #0000FF;">GetInfoByIp</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> ip<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">double</span> dIp <span style="color: #008000;">=</span> GetDoubleIp<span style="color: #000000;">&#40;</span>ip<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> WcfServiceGeoIp.<span style="color: #0000FF;">Facade</span>.<span style="color: #0000FF;">GetInfoByIp</span><span style="color: #000000;">&#40;</span>dIp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">double</span> GetDoubleIp<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> ip<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> ipSection <span style="color: #008000;">=</span> ip.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;.&quot;</span>.<span style="color: #0000FF;">ToCharArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ipSection.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Fórmula para calcular la IP ((A*256+B)*256+C)*256 + D</span>
                <span style="color: #008080; font-style: italic;">// (A * 256^3) + (B * 256^2) + (C * 256^1) + (D * 256^0)</span>
                <span style="color: #FF0000;">double</span> dIp <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span>.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>ipSection<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">256</span> <span style="color: #008000;">+</span>
                    <span style="color: #FF0000;">int</span>.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>ipSection<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">256</span> <span style="color: #008000;">+</span>
                    <span style="color: #FF0000;">int</span>.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>ipSection<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">256</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">int</span>.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>ipSection<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> dIp<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;La IP facilitada no tiene un formato correcto.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Cómo nos advierten los comentarios que nos genera VS en la clase del servicio, si hacemos cambios en los nombres de las clases, tendremos que modificar el <em>web.config</em>, en este caso, el <em>system.serviceModel</em> quedará así:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;WcfServiceGeoIp.ServiceGeoIp&quot;</span> <span style="color: #000066;">behaviorConfiguration</span>=<span style="color: #ff0000;">&quot;WcfServiceGeoIp.ServiceGeoIpBehavior&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;basicHttpBinding&quot;</span> <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;WcfServiceGeoIp.IGeoIp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dns</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;http://localizadorip.glopez.es&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/identity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/endpoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;mex&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;mexHttpBinding&quot;</span> <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;IMetadataExchange&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;behaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceBehaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;behavior</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;WcfServiceGeoIp.ServiceGeoIpBehavior&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceMetadata</span> <span style="color: #000066;">httpGetEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceDebug</span> <span style="color: #000066;">includeExceptionDetailInFaults</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/behavior<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/serviceBehaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/behaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Sólo nos faltan las consultas a base de datos, que como comentaba anteriormente, en este caso he optado por utilizar <em>LINQ</em>, así que generamos el <strong>dbml </strong>de nuestra base de datos, si estais utilizando <em>GeoLite Country</em>, sólo contiene una tabla. La clase quedará así:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> Facade
<span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">static</span> LinqDbDataContext dataContext <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinqDbDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetCountryByIp<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span> ip<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          var countries <span style="color: #008000;">=</span> from c <span style="color: #0600FF;">in</span> dataContext.<span style="color: #0000FF;">GeoIPCountryWhois</span>
                            where c.<span style="color: #0000FF;">start_long</span> <span style="color: #008000;">&lt;=</span> ip
                            orderby c.<span style="color: #0000FF;">start_long</span> descending
                            select c<span style="color: #008000;">;</span>
&nbsp;
          GeoIPCountryWhois country <span style="color: #008000;">=</span> countries.<span style="color: #0000FF;">FirstOrDefault</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
          <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>country <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
          <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> country.<span style="color: #0000FF;">country_name</span><span style="color: #008000;">;</span>
          <span style="color: #000000;">&#125;</span>
          <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
     <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> LocalizacionIp GetInfoByIp<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span> ip<span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          var countries <span style="color: #008000;">=</span> from c <span style="color: #0600FF;">in</span> dataContext.<span style="color: #0000FF;">GeoIPCountryWhois</span>
                           where c.<span style="color: #0000FF;">start_long</span> <span style="color: #008000;">&lt;=</span> ip
                           orderby c.<span style="color: #0000FF;">start_long</span> descending
                           select <span style="color: #008000;">new</span> LocalizacionIp
                           <span style="color: #000000;">&#123;</span>
                               Country <span style="color: #008000;">=</span> c.<span style="color: #0000FF;">country_name</span>,
                               CountryCode <span style="color: #008000;">=</span> c.<span style="color: #0000FF;">country_code</span>
                           <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
          LocalizacionIp countryInfo <span style="color: #008000;">=</span> countries.<span style="color: #0000FF;">FirstOrDefault</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
          <span style="color: #0600FF;">return</span> countryInfo<span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Ya tenemos nuestro servicio para localizar a los usuarios por su IP.</p>
<p>Para consumir este servicio es tan sencillo como agregar la referencia al servicio, y utilizar este código de ejemplo desde una página aspx de prueba:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     WCFServiceGeoIp.<span style="color: #0000FF;">GeoIpClient</span> servicio <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WCFServiceGeoIp.<span style="color: #0000FF;">GeoIpClient</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
     WCFServiceGeoIp.<span style="color: #0000FF;">IGeoIp</span> Iservicio <span style="color: #008000;">=</span> servicio<span style="color: #008000;">;</span>
     WCFServiceGeoIp.<span style="color: #0000FF;">LocalizacionIp</span> info <span style="color: #008000;">=</span> Iservicio.<span style="color: #0000FF;">GetInfoByIp</span><span style="color: #000000;">&#40;</span>GetPublicIp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Country name: &quot;</span> <span style="color: #008000;">+</span> info.<span style="color: #0000FF;">Country</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
     Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;br/&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
     Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Country code: &quot;</span> <span style="color: #008000;">+</span> info.<span style="color: #0000FF;">CountryCode</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>    
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetPublicIp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     <span style="color: #FF0000;">string</span> ip <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">ServerVariables</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;HTTP_X_FORWARDED_FOR&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
     <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ip <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          ip <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">ServerVariables</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;REMOTE_ADDR&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
     <span style="color: #000000;">&#125;</span>
     <span style="color: #0600FF;">return</span> ip<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>*Si ejecutáis la solución en local, no os podrá reconocer porque capturará <em>localhost </em>en vez de vuestra IP pública.</p>
<p><a href="http://www.glopez.es/wp-content/uploads/2010/03/WebServiceGeoIp.rar"><img src="http://www.glopez.es/wp-content/uploads/2010/03/descargar.png" alt="descargar" title="descargar" width="175" height="90" class="size-full wp-image-202" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/net/servicio-para-localizacion-por-ip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configurar el firewall de SQL Azure</title>
		<link>http://www.glopez.es/azure/configurar-el-firewall-de-sql-azure/</link>
		<comments>http://www.glopez.es/azure/configurar-el-firewall-de-sql-azure/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 20:11:55 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[cloud computing]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=183</guid>
		<description><![CDATA[Si estamos realizando un desarrollo con acceso a una base de datos de SQL Azure, tendremos que configurar una serie de parámetros para que nos funcione. Para tener acceso a la base de datos remotamente desde nuestro entorno de desarrollo, debemos crear una nueva regla al firewall de SQL Azure &#8211; que por defecto está [...]]]></description>
			<content:encoded><![CDATA[<p>Si estamos realizando un desarrollo con acceso a una base de datos de SQL Azure, tendremos que configurar una serie de parámetros para que nos funcione.</p>
<p>Para tener acceso a la base de datos remotamente desde nuestro entorno de desarrollo, debemos crear una nueva regla al <em>firewall </em>de SQL Azure &#8211; que por defecto está configurado para rechazar todas las peticiones – y habilitar el acceso a nuestra IP. Para esto vamos al portal de gestión de SQL Azure (<a href="http://sql.azure.com">http://sql.azure.com</a>) y accedemos a la pestaña de <em>Firewall Settings</em>.</p>
<p><a href="http://www.glopez.es/wp-content/uploads/2010/03/firewall-settings.png"><img src="http://www.glopez.es/wp-content/uploads/2010/03/firewall-settings.png" alt="firewall settings" title="firewall settings" width="612" height="247" class="aligncenter size-full wp-image-184" /></a></p>
<p>Añadimos una nueva regla indicándole nuestra IP, que nos facilita el mismo formulario en la parte inferior.<br />
Si tenemos una IP variable, podemos agregar un rango de valores. Nos advierten que la nueva regla tardará unos 5 minutos en replicarse, y no mienten <img src='http://www.glopez.es/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><a href="http://www.glopez.es/wp-content/uploads/2010/03/sql-azure-add-rule.png"><img src="http://www.glopez.es/wp-content/uploads/2010/03/sql-azure-add-rule.png" alt="sql azure add rule" title="sql azure add rule" width="466" height="253" class="aligncenter size-full wp-image-185" /></a></p>
<p>Bien, con este cambio ya podemos acceder desde la maquina local, con el Management Studio o desde nuestra aplicación con la cadena de conexión específica, que debería ser de este tipo:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">connectionString=&quot;Server=tcp:xxxxxxxxxx.database.windows.net;Database=DemoGlopez;User ID=MyUsername;Password=MyPassword;Trusted_Connection=False;Encrypt=True;&quot;</pre></div></div>

<p>Para verificar esto, en un rol de ASP.NET de un proyecto <em>Cloud Service</em>, ponemos un simple código de acceso a datos, podría servir este:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">&nbsp;
<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SqlConnection con <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Configuration</span></span>.<span style="color: #0000FF;">ConfigurationManager</span>.<span style="color: #0000FF;">ConnectionStrings</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;DemoConnectionString&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ConnectionString</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SqlCommand com <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlCommand<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;select id, nombre from Demo&quot;</span>, con<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          con.<span style="color: #0000FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
          <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SqlDataReader reader <span style="color: #008000;">=</span> com.<span style="color: #0000FF;">ExecuteReader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
          <span style="color: #000000;">&#123;</span>
               <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>reader.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
               <span style="color: #000000;">&#123;</span>
                    Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>reader<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;id&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>reader<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;nombre&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;br/&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
               <span style="color: #000000;">&#125;</span>
          <span style="color: #000000;">&#125;</span>
     <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Ejecutamos y vemos que todo funciona bien (debemos crear una tabla en nuestra base de datos y modificar la consulta del command de este ejemplo para adaptarlo a nuestro entorno).</p>
<p>Ahora hacemos un <em>Deploy </em>de esta simple aplicación y veremos que falla (tendremos que deshabilitar los <em>customErrors </em>para que se nos muestre el mensaje de error).</p>
<p>Parece que seguimos teniendo problemas de acceso a SQL Azure, asi que volvemos al panel de gestión y hacemos un <em>Test Connectivity</em> (hay que tener seleccionada la base de datos), comprobamos que la conexión falla desde la IP del servidor dónde está alojada la aplicación.</p>
<p>Volvemos al <em>Firewall Settings</em> y marcamos el check de <strong>Allow Microsoft Services access to this server</strong>. Repetimos el <em>Test Connectivity</em> y ahora funciona.</p>
<p><a href="http://www.glopez.es/wp-content/uploads/2010/03/test-ok.png"><img src="http://www.glopez.es/wp-content/uploads/2010/03/test-ok.png" alt="test ok" title="test ok" width="341" height="265" class="aligncenter size-full wp-image-186" /></a></p>
<p>Bien, volvemos a ejecutar nuestra aplicación, pero aún sigue fallando!</p>
<div id="attachment_187" class="wp-caption aligncenter" style="width: 908px"><a href="http://www.glopez.es/wp-content/uploads/2010/03/error-sql-azure.png"><img src="http://www.glopez.es/wp-content/uploads/2010/03/error-sql-azure.png" alt="Cannot open server &#039;xxxxxxxxxx&#039; requested by the login. Client with IP address &#039;65.52.138.89&#039; is not allowed to access the server." title="error sql azure" width="898" height="338" class="size-full wp-image-187" /></a><p class="wp-caption-text">Cannot open server 'xxxxxxxxxx' requested by the login. Client with IP address '65.52.138.89' is not allowed to access the server.</p></div>
<p>Esto es un problema de la plataforma, debería funcionarnos, pero parece que hay un fallo con los rangos de IP que tienen permitidos internamente (info: <a href="http://tinyurl.com/yf46fxk">http://tinyurl.com/yf46fxk</a>). Así que nos toca añadir la IP del servidor como regla en nuestro firewall de SQL Azure hasta que esto se solucione.</p>
<p>Debería quedarnos una configuración de firewall así:</p>
<p><a href="http://www.glopez.es/wp-content/uploads/2010/03/sql-azure-firewall-2.png"><img src="http://www.glopez.es/wp-content/uploads/2010/03/sql-azure-firewall-2.png" alt="sql azure firewall 2" title="sql azure firewall 2" width="570" height="195" class="aligncenter size-full wp-image-188" /></a></p>
<p>Y ahora nuestra aplicación funcionará correctamente.</p>
<p>Existe la posibilidad de administrar las reglas del <em>firewall </em>mediante <em>procedures </em>de la base de datos si no queremos utilizar el portal de gestión. Accedemos a la base de datos <strong>master </strong>de nuestro SQL Azure y utilizamos las siguientes sentencias:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Reglas existentes</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> sys<span style="color: #66cc66;">.</span>firewall_rules
&nbsp;
<span style="color: #808080; font-style: italic;">-- Añadir nueva regla de firewall</span>
exec sp_set_firewall_rule N<span style="color: #ff0000;">'DemoTSQL'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'0.1.1.0'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'0.1.1.255'</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--Modificar una regla de firewall</span>
exec sp_set_firewall_rule N<span style="color: #ff0000;">'DemoTSQL'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'0.1.1.1'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'0.1.1.255'</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--Eliminar una regla de firewall</span>
exec sp_delete_firewall_rule N<span style="color: #ff0000;">'DemoTSQL'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/azure/configurar-el-firewall-de-sql-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cambiar la versión de la base de datos [SQL Azure]</title>
		<link>http://www.glopez.es/bbdd/cambiar-la-version-de-la-base-de-datos-sql-azure/</link>
		<comments>http://www.glopez.es/bbdd/cambiar-la-version-de-la-base-de-datos-sql-azure/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 09:10:23 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[BBDD]]></category>
		<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[cloud computing]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=180</guid>
		<description><![CDATA[Ayer publicaron en el SQL Azure Team Blog la noticia de la primera actualización al servicio de SQL Azure, esta actualización consiste en una serie de mejoras recogidas del feedback de la comunidad, toda la info. Me parece interesante la posibilidad de cambiar la edición de la base de datos (Web edition &#8211; Business edition) [...]]]></description>
			<content:encoded><![CDATA[<p>Ayer publicaron en el <strong>SQL Azure Team Blog</strong> la noticia de la primera actualización al servicio de <em>SQL Azure</em>, esta actualización consiste en una serie de mejoras recogidas del feedback de la comunidad, <a href="http://blogs.msdn.com/sqlazure/archive/2010/02/17/9965464.aspx">toda la info</a>.</p>
<p>Me parece interesante la posibilidad de cambiar la edición de la base de datos (<em>Web edition &#8211; Business edition</em>) con un simple comando:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> database_name
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #993333; font-weight: bold;">MODIFY</span> <span style="color: #66cc66;">&#40;</span>MAXSIZE <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">|</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#125;</span> GB<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/bbdd/cambiar-la-version-de-la-base-de-datos-sql-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo cuenta Azure las horas de proceso de instancia</title>
		<link>http://www.glopez.es/azure/como-cuenta-azure-las-horas-de-proceso-de-instancia/</link>
		<comments>http://www.glopez.es/azure/como-cuenta-azure-las-horas-de-proceso-de-instancia/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 17:29:55 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[cloud computing]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=175</guid>
		<description><![CDATA[Cuando empiezas a hacer cálculos sobre estimaciones de costes para subir una aplicación a la nube, enseguida te das cuenta dónde están los costes reales, en las horas de proceso y en el ancho de banda. En una aplicación con un tráfico que empieza a ser considerable ( por ejmeplo, &#62; 5GB/hora). Las horas de [...]]]></description>
			<content:encoded><![CDATA[<p>Cuando empiezas a hacer cálculos sobre estimaciones de costes para subir una aplicación a la nube, enseguida te das cuenta dónde están los costes reales, en las <span style="text-decoration: underline;">horas de proceso</span> y en el<span style="text-decoration: underline;"> ancho de banda</span>. En una aplicación con un tráfico que empieza a ser considerable ( por ejmeplo, &gt; 5GB/hora). Las horas de proceso, pueden representar el <strong>25%</strong> de la factura. Por lo tanto es importante conocer como computa Microsoft las horas que consumimos de proceso.</p>
<p>Lo primero que hay que saber, es que aunque no hagas un uso real de cpu, pagas por todas las horas que tengas tu aplicación levantada, y si tienes la aplicación levantada 5 minutos, pagas una hora completa.</p>
<p>Hasta aquí, no son noticias geniales, pero funciona similar a otros productos como <a href="http://aws.amazon.com/ec2">Amazon EC2</a>.</p>
<p>Lo que me ha parecido curioso y creo que es importante conocer, es que cuando mantienes una aplicación en estado de <em>Parada </em>o <em>suspendida</em>, continua computando horas. Eso quiere decir que si mantienes el entorno de producción levantado y el de <em>staging</em>, <em>stopped</em>, estás consumiendo <strong>48h</strong> al día!</p>
<p>Para evitar esto, tenemos que eliminar la aplicación.</p>
<p><a href="http://www.glopez.es/wp-content/uploads/2010/02/servicio-azure.png"><img class="aligncenter size-medium wp-image-176" title="servicio azure" src="http://www.glopez.es/wp-content/uploads/2010/02/servicio-azure-300x138.png" alt="servicio azure" width="300" height="138" /></a></p>
<p>Si mantenemos un entorno como el de la imagen, gastamos 1h de proceso, si le damos a <em>suspend</em>, continuaremos consumiendo esa hora de proceso, debemos hacer un <em>Delete </em>para dejar de consumir esos recursos. Los dos entornos debería aparecernos como el de <em>Production </em>de la imagen.</p>
<p>Visto en: <a href="http://dunnry.com/blog/HowDoIStopTheBillingMeterInWindowsAzure.aspx">blog de Ryan Dunn</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/azure/como-cuenta-azure-las-horas-de-proceso-de-instancia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Más de 100.000 iconos, gratis</title>
		<link>http://www.glopez.es/iconos/mas-de-100-000-iconos-gratis/</link>
		<comments>http://www.glopez.es/iconos/mas-de-100-000-iconos-gratis/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 19:53:18 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[Iconos]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=168</guid>
		<description><![CDATA[En mi faceta de hunter insaciable de iconos, he encontrado el siguiente enlace dónde recopilan más de 100.000 iconos gratuitos en una galería, con su imagen de previsualización y detallando su licencia de uso! http://www.iconfinder.net/free_icons/ Algunos son realmente &#8220;inútiles&#8221;, pero están tan bien hechos]]></description>
			<content:encoded><![CDATA[<p>En mi faceta de <em>hunter</em> insaciable de iconos, he encontrado el siguiente enlace dónde recopilan más de 100.000 iconos gratuitos en una galería, con su imagen de previsualización y detallando su licencia de uso!</p>
<p><a href="http://www.iconfinder.net/free_icons/"><img src="http://www.glopez.es/wp-content/uploads/2010/01/icons.png" alt="icons" title="icons" width="566" height="229" class="aligncenter size-full wp-image-170" /></a></p>
<p><a href="http://www.iconfinder.net/free_icons/">http://www.iconfinder.net/free_icons/</a></p>
<p>Algunos son realmente &#8220;inútiles&#8221;, pero están tan bien hechos <img src='http://www.glopez.es/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/iconos/mas-de-100-000-iconos-gratis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Routing en ASP.NET Web forms</title>
		<link>http://www.glopez.es/net/routing-en-asp-net-web-forms/</link>
		<comments>http://www.glopez.es/net/routing-en-asp-net-web-forms/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 01:36:41 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=161</guid>
		<description><![CDATA[Con el enrutamiento, podemos conseguir transformar las URL de nuestra aplicación para que sean más amigables al usuario, de tal manera, que no tiene porque hacerse referencia al fichero físico (.aspx, .html, …) por ejemplo, si tradicionalmente tenemos una URL del tipo: http://www.dominio.com/Post.aspx?category=7&#38;id=14 podemos conseguir una url de este otro tipo http://www.dominio.com/Post/Eventos/14 Esta característica es [...]]]></description>
			<content:encoded><![CDATA[<p>Con el enrutamiento, podemos conseguir transformar las URL de nuestra aplicación para que sean más amigables al usuario, de tal manera, que no tiene porque hacerse referencia al fichero físico (.aspx, .html, …) por ejemplo, si tradicionalmente tenemos una URL del tipo: <em>http://www.dominio.com/Post.aspx?category=7&amp;id=14</em> podemos conseguir una url de este otro tipo<em> http://www.dominio.com/Post/Eventos/14</em></p>
<p>Esta característica es una de las ventajas del framework <a title="ASP.NET MVC" href="http://www.asp.net/(S(d35rmemuuono1wvm1gsp2n45))/mvc/" target="_self">ASP.NET MVC</a>, pero lo que voy a tratar de explicar aquí es como activar esto en una aplicación <em>web site</em> o un proyecto <em>web application</em>. Para poder hacerlo, es necesaria la versión <strong>3.5 SP1 del .NET framework</strong>.</p>
<p>Creamos una aplicación web ASP.NET en visual studio 2008. Lo primero que tenemos que hacer es agregarnos una referencia al ensamblado<strong> System.Web.Routing</strong>, que es quien nos proveerá de toda la funcionalidad de enrutado.</p>
<p style="text-align: center;"><a href="http://www.glopez.es/wp-content/uploads/2010/01/referencia-routing.png"><img class="size-medium wp-image-162 aligncenter" title="referencia routing" src="http://www.glopez.es/wp-content/uploads/2010/01/referencia-routing-300x195.png" alt="referencia routing" width="300" height="195" /></a></p>
<p>Ahora vamos al fichero <em>web.config</em>, y según con que versión de IIS vayamos a trabajar, debemos agregar las siguientes configuraciones.</p>
<p>- IIS 6.0 o IIS 7.0 en <em>Classic mode</em></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>      
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;RoutingModule&quot;</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Routing.UrlRoutingModule, </span>
<span style="color: #009900;">               System.Web.Routing, </span>
<span style="color: #009900;">               Version=3.5.0.0, Culture=neutral, </span>
<span style="color: #009900;">               PublicKeyToken=31bf3856ad364e35&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>- IIS 7.0 <em>Integrated mode</em></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules</span> <span style="color: #000066;">runAllManagedModulesForAllRequests</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;UrlRoutingModule&quot;</span></span>
<span style="color: #009900;">             <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Routing.UrlRoutingModule, </span>
<span style="color: #009900;">                   System.Web.Routing, Version=3.5.0.0, </span>
<span style="color: #009900;">                   Culture=neutral, </span>
<span style="color: #009900;">                   PublicKeyToken=31BF3856AD364E35&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;UrlRoutingHandler&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">preCondition</span>=<span style="color: #ff0000;">&quot;integratedMode&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;UrlRouting.axd&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.HttpForbiddenHandler, </span>
<span style="color: #009900;">                  System.Web, Version=2.0.0.0, Culture=neutral, </span>
<span style="color: #009900;">                  PublicKeyToken=b03f5f7f11d50a3a&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong><span style="text-decoration: underline;">NOTA</span></strong>: para trabajar en local, aunque tengamos IIS 7.0 instalado, recordad que trabajamos con  el servidor web de visual studio 2008 (<em>Cassini</em>), y hay que añadir la configuración de los <strong>httpModules</strong>.</p>
<p>Ahora nos vamos al fichero <em>global.asax</em> (lo añadimos si no lo tenemos), incluimos  el <em>using System.Web.Routing</em> y creamos la siguiente función (que llamaremos desde el método <em>Application_Start</em>).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> RegisterRoutes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     RouteTable.<span style="color: #0000FF;">Routes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>
          <span style="color: #666666;">&quot;NombreRuta&quot;</span>,
          <span style="color: #008000;">new</span> Route<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;nivel1/{cualquiercosa}&quot;</span>,
                             <span style="color: #008000;">new</span> DemoRouteHandler<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Demo.aspx&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Application_Start<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     RegisterRoutes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Aquí debemos registrar todas las rutas que queramos controlar, por ejemplo, en este caso, solo vamos a capturar las peticiones a las URL del tipo <em>http://server/nivel1/cualquiervalor</em> y lo que haremos será enviar esa petición a la página<em> Demo.aspx</em>.<br />
Si recibimos una petición a una URL que no cumple ningún patrón de los registrados, la aplicación devolverá un error 404.</p>
<p>Nos falta crear la clase <em>DemoRouteHandler</em> que implementa <em>IRouteHandler</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Routing</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Compilation</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> DemoRouting
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> DemoRouteHandler <span style="color: #008000;">:</span> IRouteHandler
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">string</span> _virtualPath<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> DemoRouteHandler<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> virtualPath<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _virtualPath <span style="color: #008000;">=</span> virtualPath<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> IHttpHandler GetHttpHandler<span style="color: #000000;">&#40;</span>RequestContext requestContext<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var display <span style="color: #008000;">=</span> BuildManager.<span style="color: #0000FF;">CreateInstanceFromVirtualPath</span><span style="color: #000000;">&#40;</span>
                            _virtualPath, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Page<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> IHttpHandler<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> display<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Si creamos la página <em>Demo.aspx</em>, en el <em>Page_Load</em> podemos acceder a la propiedad Url de la propiedad Request de la instancia Page.<br />
Ya tenemos activado el enrutamiento en nuestra aplicación, podemos lanzarla desde vs y comprobarlo accediendo directamente a la url que cumpla el patrón.</p>
<p>Podemos descargar un ejemplo más bonito y completo de <a href="http://code.msdn.microsoft.com/mag200901Extreme">msdn magazine</a>  y profundizar con las reglas de enrutado en este <a href="http://msdn.microsoft.com/es-es/library/cc668201.aspx">artículo</a> de msdn.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/net/routing-en-asp-net-web-forms/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Ideas para mejorar Windows Azure?</title>
		<link>http://www.glopez.es/azure/ideas-para-mejorar-windows-azure/</link>
		<comments>http://www.glopez.es/azure/ideas-para-mejorar-windows-azure/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 23:35:01 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[cloud computing]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=156</guid>
		<description><![CDATA[Si eres de los que han podido probar la plataforma windows Azure en este mes de lanzamiento y has encontrado puntos a mejorar o funcionalidades interesantes que te han faltado, los chicos de Microsoft tienen habilitado un espacio para que compartas esas propuestas o votes por las presentadas por otros usuarios. Me parece una gran [...]]]></description>
			<content:encoded><![CDATA[<p>Si eres de los que han podido probar la plataforma windows Azure en este mes de lanzamiento y has encontrado puntos a mejorar o funcionalidades interesantes que te han faltado, los chicos de Microsoft tienen habilitado un espacio para que compartas esas propuestas o votes por las presentadas por otros usuarios. Me parece una gran idea y una buena manera de recibir <em>feedback</em> para un producto nuevo.</p>
<p><a href="http://www.mygreatwindowsazureidea.com">www.mygreatwindowsazureidea.com</a></p>
<p>Leído hoy en el <a href="http://blogs.msdn.com/windowsazure/archive/2010/01/25/do-you-have-a-great-windows-azure-idea.aspx"><strong>Team Blog de Windows Azure.</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/azure/ideas-para-mejorar-windows-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>freaklances</title>
		<link>http://www.glopez.es/internet/freaklances/</link>
		<comments>http://www.glopez.es/internet/freaklances/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 22:44:28 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[series]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=149</guid>
		<description><![CDATA[freaklances, acabo de descubrir esta miniserie. A mi me a parecido que tiene buena pinta, tanto la temática como la estética me gustan, seguiremos su evolución Si queréis conocer más, los autores tienen un blog: http://freaklances.blogspot.com]]></description>
			<content:encoded><![CDATA[<p>freaklances, acabo de descubrir esta miniserie.</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/05scoCk8KSc&#038;hl=es_ES&#038;fs=1&#038;color1=0x3a3a3a&#038;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/05scoCk8KSc&#038;hl=es_ES&#038;fs=1&#038;color1=0x3a3a3a&#038;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p>A mi me a parecido que tiene buena pinta, tanto la temática como la estética me gustan, seguiremos su evolución <img src='http://www.glopez.es/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
Si queréis conocer más, los autores tienen un blog: <a href="http://freaklances.blogspot.com">http://freaklances.blogspot.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/internet/freaklances/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Añadiendo Adsense a entredas antiguas de WP</title>
		<link>http://www.glopez.es/internet/anadiendo-adsense-a-entredas-antiguas-de-wp/</link>
		<comments>http://www.glopez.es/internet/anadiendo-adsense-a-entredas-antiguas-de-wp/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 03:12:14 +0000</pubDate>
		<dc:creator>gerard</dc:creator>
				<category><![CDATA[Adsense]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[publicidad]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.glopez.es/?p=143</guid>
		<description><![CDATA[He añadido publicidad al blog, a partir de ahora empieza el camino a la riqueza, no pretendo que me genere ingresos, simplemente hacía tiempo que quería probar el funcionamiento de Google Adsense y su integración con Google Analytics. De momento, el registro y la configuración del bloque de publicidad me han dejado la sensación que [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.glopez.es/wp-content/uploads/2010/01/adsense.png"><img class="alignleft size-full wp-image-144" title="adsense" src="http://www.glopez.es/wp-content/uploads/2010/01/adsense.png" alt="adsense" width="150" height="38" /></a> He añadido publicidad al blog, <span style="text-decoration: line-through;">a partir de ahora empieza el camino a la riqueza,</span> no pretendo que me genere ingresos, simplemente hacía tiempo que quería probar el funcionamiento de <strong>Google Adsense</strong> y su integración con <strong>Google Analytics</strong>.</p>
<p>De momento, el registro y la configuración del bloque de publicidad me han dejado la sensación que son claramente mejorables. Al configurar el bloque he echado en falta una <em>preview </em>del bloque<em> </em>conforme ibas cambiando los parámetros.</p>
<p>Pues como mi intención es la de probar, he recogido de <a href="http://www.nosolocodigo.com/mostrar-publicidad-solo-en-posts-antiguos-en-wordpress" target="_self">nosolocodigo</a> una función php para añadir a nuestro theme de <em>wordpress </em>para que sólo aparezca la publicidad en los post con más de X días. Así no es intrusivo para los fieles seguidores (1,5).</p>
<p>Lo único que debemos hacer es copiar la siguiente función en el fichero <strong>functions.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> is_old_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$days</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$post_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>post<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>ID<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000088;">$current_date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$days</span> <span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$post_id</span> <span style="color: #339933;">=</span> get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$post_date</span> <span style="color: #339933;">=</span> mysql2date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'U'</span><span style="color: #339933;">,</span><span style="color: #000088;">$post_id</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>post_date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$cunning_math</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post_date</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current_date</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$cunning_math</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Con la variable <strong>days </strong>declarada en la segunda línea, podemos variar la antigüedad de los post en los que queremos que aparezca la publicidad.<br />
Y después, en la página dónde queramos añadir la publicidad, ponemos:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_old_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    script para cargar la PUBLICIDAD
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.glopez.es/internet/anadiendo-adsense-a-entredas-antiguas-de-wp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

