<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>fboiton&#039;s blog &#187; web application</title>
	<atom:link href="http://www.fboiton.com/tag/web-application/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fboiton.com</link>
	<description>Blog Técnico y personal: Ideas, Guias, Tutoriales, Comentarios, Pensamientos, Entre otros.</description>
	<lastBuildDate>Sun, 05 Feb 2012 22:01:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ASP.NET Website Generic Handlers</title>
		<link>http://www.fboiton.com/aspnet-website-generic-handlers</link>
		<comments>http://www.fboiton.com/aspnet-website-generic-handlers#comments</comments>
		<pubDate>Thu, 24 Jun 2010 15:22:35 +0000</pubDate>
		<dc:creator>fboiton</dc:creator>
				<category><![CDATA[Desarrollo de Software]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[practices]]></category>
		<category><![CDATA[web application]]></category>
		<category><![CDATA[webforms]]></category>

		<guid isPermaLink="false">http://www.fboiton.com/?p=32</guid>
		<description><![CDATA[Existen ocasiones que necesitamos dejar por un lado el HTML y responder XML, json, etc. Muchas veces hemos utilizado una página ASPX y el Response.Write para estos fines, sin embargo, existe otra opción… Los ASP.NET Generic Web Handler cuando trabajamos &#8230; <a href="http://www.fboiton.com/aspnet-website-generic-handlers">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Existen ocasiones que necesitamos dejar por un lado el HTML y responder XML, json, etc. Muchas veces hemos utilizado una página ASPX y el Response.Write para estos fines, sin embargo, existe otra opción… Los <em>ASP.NET Generic Web Handler </em>cuando trabajamos con <em>ASP.NET WebSites</em>.</p>
<p>No es que sea totalmente malo utilizar una ASPX, en realidad el punto es que toda ASPX hereda de System.Web.UI.Page y éste incluye ovehead que no necesitamos para lo que necesitamos.</p>
<p>Primero agregamos al proyecto nuestro Handler</p>
<p><a href="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="294" alt="image" src="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image_thumb.png" width="547" border="0" /></a> </p>
<p>Una vez creado, obtendremos el código definido por el template</p>
<p><a href="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image_3.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="280" alt="image" src="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image_thumb_3.png" width="412" border="0" /></a> </p>
<p>Quien hace acá la magia es esta directiva:</p>
<p><a href="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image_4.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="26" alt="image" src="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image_thumb_4.png" width="478" border="0" /></a> </p>
<p>Básicamente, define que la Clase “Handler” se debe instanciar para manejar la respuesta al llamar a dicho archivo.</p>
<p>Recordemos definir siempre el content type, el cual en este ejemplo definiré para javascript “<em>application/x-javascript</em>” y la respuesta (que para efectos de este post lo dejaré con un Response.Write) la modificaré para retornar un array en formato json, lo que nos lleva a una clase así:</p>
<p> <code>public class Handler : IHttpHandler {    <br />&#160;&#160;&#160; public void ProcessRequest (HttpContext context) {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Response.ContentType = &quot;application/x-javascript&quot;;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Response.Write(&quot;{testlist:['value 1','value 2', 'value 3']}&quot;);     <br />&#160;&#160;&#160; }     <br />&#160;&#160;&#160; public bool IsReusable {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; get {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return false;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br />&#160;&#160;&#160; }
</p>
<p>}</p>
<p> </code>
</p>
<p>Al correr el scritp este es el resultado:</p>
<p><a href="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image_5.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="80" alt="image" src="http://www.fboiton.com/images/ASP.NETCustomWebHandlerGenericHandlers_7E5D/image_thumb_5.png" width="506" border="0" /></a> </p>
<p>Aclaro… Existen formas para serializara diferentes formatos, para relacionarlo con el ejemplo pueden ver la documentación en msdn de <a href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.aspx">Script Serialization</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fboiton.com/aspnet-website-generic-handlers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

