<?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>Dot Net Thoughts &#187; Http Handler</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/http-handler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to use Session objects in an HttpHandler</title>
		<link>http://www.dotnetthoughts.net/2009/09/15/how-to-use-session-objects-in-an-httphandler/</link>
		<comments>http://www.dotnetthoughts.net/2009/09/15/how-to-use-session-objects-in-an-httphandler/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 07:24:53 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Http Handler]]></category>
		<category><![CDATA[Session]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=385</guid>
		<description><![CDATA[In my previous post, Captcha using ASP.Net and C#, you may noticed that I am not talking about how can I validate the user is entering correct value or not. I thought of using Sessions for this purpose, like in the HTTP Handler, I wrote some code like context.Session[&#34;captcha&#34;] = drawString; But that code failed, [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post, <a href="http://anuraj.wordpress.com/2009/09/15/captcha-using-asp-net-and-c/">Captcha using ASP.Net and C#</a>, you may noticed that I am not talking about how can I validate the user is entering correct value or not. I thought of using Sessions for this purpose, like in the HTTP Handler, I wrote some code like</p>
<pre class="brush: csharp;">
context.Session[&quot;captcha&quot;] = drawString;
</pre>
<p>But that code failed, by throwing a Null Reference exception. After debugging I found the session object is coming as NULL. Then after doing a little search I found a nice post about how can we use session state in Http Handlers. For this you have to implement an empty interface, IRequiresSessionState, which in the available in the System.Web.SessionState namespace, you have to add reference of this namespace in your code, implement the interface, and you can use session in the Http Handler.</p>
<pre class="brush: csharp;">
using System.Web.SessionState;

public class Handler : IHttpHandler, IRequiresSessionState
{
//Your implementation.
}
</pre>
<p>You can also use IReadOnlySessionState interface instead of IRequiresSessionState, which gives read only access to the session objects.</p>
<p>Now you can save the drawString value to the session state and in the C# code, you can read it from session and check with the user entry.</p>
<p>You can get more details from this post :<a href="http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/how-to-use-session-values-in-an-httphandler.aspx" target="_blank">How to use Session values in an HttpHandler</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/09/15/how-to-use-session-objects-in-an-httphandler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
