<?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>dotnet thoughts &#187; ASP.Net Handler</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/asp-net-handler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Implementing ASP.Net Forms Authentication with Active Directory Membership Provider</title>
		<link>http://www.dotnetthoughts.net/2010/06/29/implementing-asp-net-forms-authentication-with-active-directory-membership-provider/</link>
		<comments>http://www.dotnetthoughts.net/2010/06/29/implementing-asp-net-forms-authentication-with-active-directory-membership-provider/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 07:52:28 +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[Active Directory Authentication]]></category>
		<category><![CDATA[ASP.Net Handler]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=958</guid>
		<description><![CDATA[ActiveDirectoryMembership provider is used manage users against Active Directory, which helps to create Single Sign On for intranet application. Here is a basic implementation, which used to Authenticate users against Active Directory, using Login Control. We need to modify the &#8230; <a href="http://www.dotnetthoughts.net/2010/06/29/implementing-asp-net-forms-authentication-with-active-directory-membership-provider/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>ActiveDirectoryMembership provider is used manage users against Active Directory, which helps to create Single Sign On for intranet application. Here is a basic implementation, which used to Authenticate users against Active Directory, using Login Control.</p>
<p>We need to modify the web.config, like the implementation of Forms Authentication in ASP.Net.</p>
<p>Create / Add a connection string to active directory database.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;connectionStrings&gt;
&lt;add name=&quot;ADConnectionString&quot; connectionString=&quot;LDAP://DOMAIN.SUBDOMAIN/DC=DOMAIN,DC= SUBDOMAIN &quot;/&gt;
&lt;/connectionStrings&gt;
</pre>
<p>Configure Membership node in the web.config with ActiveDirectoryMembershipProvider.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;membership defaultProvider=&quot;MembershipADProvider&quot;&gt;
  &lt;providers&gt;
    &lt;add name=&quot;MembershipADProvider&quot;
         type=&quot;System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;
         applicationName=&quot;dotnetthoughts&quot;
         connectionStringName=&quot; ADConnectionString &quot;
         attributeMapUsername=&quot;sAMAccountName&quot;/&gt;
  &lt;/providers&gt;
&lt;/membership&gt;
</pre>
<p>You can also provide the Username / Password in this using connectionUsername , connectionPassword attributes.</p>
<p>Modify the Authentication mode and Authorization nodes for controlling the access permissions. Currently I am using Forms Authentication defaults. (default.aspx &#8211; Home Page, and Login.aspx &#8211; Login Page)</p>
<pre class="brush: xml; title: ; notranslate">
&lt;authentication mode=&quot;Forms&quot; /&gt;
&lt;authorization&gt;
    &lt;deny users=&quot;?&quot; /&gt;
    &lt;allow users=&quot;*&quot; /&gt;
&lt;/authorization&gt;
</pre>
<p>Almost done. Now drag and drop Login control from Toolbox > Login tab to Login.aspx. Run the application, say OK to the Debug mode confirmation from Visual Studio. As we are configured the Authentication provider we don’t need to write any Code to Authentication.</p>
<p>If you don&#8217;t want to use login control, you can do something like this in the code behind for the authentication.</p>
<pre class="brush: csharp; title: ; notranslate">
if (Membership.ValidateUser(this.txtUsername.Text, this.txtPassword.Text))
{
    FormsAuthentication.RedirectFromLoginPage(this.txtUsername.Text, false);
}
else
{
    Response.Write(&quot;Authentication failed.\nUsername / Password Invalid&quot;);
}
</pre>
<p>Thanks to Sreenaja for the initial implementation. Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2009/07/30/implementing-windows-authentication-in-asp-net-on-iis-7/" title="Permanent link to Implementing Windows authentication in ASP.NET on IIS 7">Implementing Windows authentication in ASP.NET on IIS 7</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/26/how-to-upload-file-using-httpwebrequest-class/" title="Permanent link to How to upload file using HttpWebRequest class">How to upload file using HttpWebRequest class</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/03/30/using-custom-controls-from-app_code-folder/" title="Permanent link to Using custom controls from App_Code folder">Using custom controls from App_Code folder</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/11/a-simple-chat-script-using-asp-net-c/" title="Permanent link to A Simple Chat script using ASP.Net C#">A Simple Chat script using ASP.Net C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/04/05/large-file-uploads-in-asp-net/" title="Permanent link to Large file uploads in ASP.Net">Large file uploads in ASP.Net</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/06/29/implementing-asp-net-forms-authentication-with-active-directory-membership-provider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Captcha using ASP.Net and C#</title>
		<link>http://www.dotnetthoughts.net/2009/09/15/captcha-using-asp-net-and-c/</link>
		<comments>http://www.dotnetthoughts.net/2009/09/15/captcha-using-asp-net-and-c/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 06:49:59 +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[ASP.Net Handler]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Captcha]]></category>
		<category><![CDATA[Drawing]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=380</guid>
		<description><![CDATA[Few days back, I got some question related to Captcha (security mechanism, which helps web masters to avoid spam) in a Forum. So I thought of implementing one. I got few nice scripts in Code Project, its a simple implementation, &#8230; <a href="http://www.dotnetthoughts.net/2009/09/15/captcha-using-asp-net-and-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Few days back, I got some question related to Captcha (security mechanism, which helps web masters to avoid spam) in a Forum. So I thought of implementing one. I got few nice scripts in Code Project, its a simple implementation, no too much logic and not too complex to understand. Also I am using an HTTP Handler instead of ASPX Page, for the implementation.</p>
<pre class="brush: csharp; title: ; notranslate">
using (Bitmap b = new Bitmap(150, 40, PixelFormat.Format32bppArgb))
        {
            using (Graphics g = Graphics.FromImage(b))
            {
                Rectangle rect = new Rectangle(0, 0, 149, 39);
                g.FillRectangle(Brushes.White, rect);

                // Create string to draw.
                Random r = new Random();
                int startIndex = r.Next(1, 5);
                int length = r.Next(5, 10);
                String drawString = Guid.NewGuid().ToString().Replace(&quot;-&quot;, &quot;0&quot;).Substring(startIndex, length);

                // Create font and brush.
                Font drawFont = new Font(&quot;Arial&quot;, 16, FontStyle.Italic | FontStyle.Strikeout);
                using (SolidBrush drawBrush = new SolidBrush(Color.Black))
                {
                    // Create point for upper-left corner of drawing.
                    PointF drawPoint = new PointF(15, 10);

                    // Draw string to screen.
                    g.DrawRectangle(new Pen(Color.Red, 0), rect);
                    g.DrawString(drawString, drawFont, drawBrush, drawPoint);
                }
                b.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                context.Response.ContentType = &quot;image/jpeg&quot;;
                context.Response.End();
            }
        }
</pre>
<p>I wrote the code in the Process Request event in HTTPHandler.<br />
And to use this in your pages you can create an IMG tag with src attribute pointing to this.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;img src=&quot;myhandler.ashx&quot; /&gt;
</pre>
<p>Note: Some time ASP.Net caches the image, so you may need to pass some GUID as querystring in the Handler.</p>
<p>Update: Sometime we may need to refresh the Captcha image, without post back, here is a simple javascript which will refresh the captcha image without post back.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
        function RefreshCaptcha() {
            var img = document.getElementById(&quot;imgCaptcha&quot;);
            img.src = &quot;Handler.ashx?query=&quot; + Math.random();
        }
&lt;/script&gt;
&lt;div&gt;
&lt;img src=&quot;Handler.ashx&quot; id=&quot;imgCaptcha&quot; /&gt;
&lt;a href=&quot;#&quot; onclick=&quot;javascript:RefreshCaptcha();&quot;&gt;Refresh&lt;/a&gt;
&lt;/div&gt;
</pre>
<p>Here is the screenshot of web page using Captcha.</p>
<div id="attachment_387" class="wp-caption alignnone" style="width: 356px"><a href="http://anuraj.files.wordpress.com/2009/09/captcha.jpg"><img src="http://anuraj.files.wordpress.com/2009/09/captcha.jpg" alt="Captcha - Security Image using ASP.Net and C#" title="Captcha - Security Image using ASP.Net and C#" width="346" height="174" class="size-full wp-image-387" /></a><p class="wp-caption-text">Captcha - Security Image using ASP.Net and C#</p></div>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2009/09/15/creating-captcha-html-helper/" title="Permanent link to Creating Captcha HTML Helper">Creating Captcha HTML Helper</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/15/how-to-use-session-objects-in-an-httphandler/" title="Permanent link to How to use Session objects in an HttpHandler">How to use Session objects in an HttpHandler</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/04/20/simple-autosuggest-textbox-using-jquery/" title="Permanent link to Simple AutoSuggest Textbox using JQuery">Simple AutoSuggest Textbox using JQuery</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/07/30/implementing-windows-authentication-in-asp-net-on-iis-7/" title="Permanent link to Implementing Windows authentication in ASP.NET on IIS 7">Implementing Windows authentication in ASP.NET on IIS 7</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/11/a-simple-chat-script-using-asp-net-c/" title="Permanent link to A Simple Chat script using ASP.Net C#">A Simple Chat script using ASP.Net C#</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/09/15/captcha-using-asp-net-and-c/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

