<?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>Adnan Rashid &#187; asp.net</title>
	<atom:link href="http://www.adnan-rashid.com/tag/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adnan-rashid.com</link>
	<description>Web Technologist</description>
	<lastBuildDate>Wed, 23 Jun 2010 20:43:53 +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>Multiline TextBox Length Validation</title>
		<link>http://www.adnan-rashid.com/2009/01/10/multiline-textbox-length-validation/</link>
		<comments>http://www.adnan-rashid.com/2009/01/10/multiline-textbox-length-validation/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 04:00:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://blog.wtesolutions.com/?p=106</guid>
		<description><![CDATA[Unlike the normal TextBox, the MaxLength property doesnt work for MultiLine TextBox. Heres a small trick to solve the problem: &#60;asp:TextBox ID=&#34;txtExample&#34; runat=&#34;server&#34; TextMode=&#34;MultiLine&#34; /&#62; &#60;asp:RegularExpressionValidator ID=&#34;revExample&#34; runat=&#34;server&#34; ControlToValidate=&#34;txtExample&#34; ValidationExpression=&#34;[\s\S]{1,200}&#34; Display=&#34;Dynamic&#34; ErrorMessage=&#34;Length cannot be greater than 200 characters&#34; /&#62; The above markup validates the revExample TextBox / textarea and limits the max characters to 200. [...]]]></description>
			<content:encoded><![CDATA[<p>Unlike the normal TextBox, the MaxLength property doesnt work for MultiLine TextBox. Heres a small trick to solve the problem:</p>
<pre name="code" class="html">
&lt;asp:TextBox ID=&quot;txtExample&quot; runat=&quot;server&quot; TextMode=&quot;MultiLine&quot; /&gt;

&lt;asp:RegularExpressionValidator ID=&quot;revExample&quot; runat=&quot;server&quot;
ControlToValidate=&quot;txtExample&quot; ValidationExpression=&quot;[\s\S]{1,200}&quot;
Display=&quot;Dynamic&quot; ErrorMessage=&quot;Length cannot be greater than 200 characters&quot; /&gt;
</pre>
<p>The above markup validates the revExample TextBox / textarea and limits the max characters to 200. By modifying the regular expressions, we can validate fields for any scenario. If you are looking for some Regular Expressions to get started out, just point your browser to <a title="Regular Expression Library" href="http://regexlib.com/" target="_blank">http://regexlib.com/</a></p>
<p>Cheers!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.adnan-rashid.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.adnan-rashid.com/2009/01/10/multiline-textbox-length-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asp.Net Read Reciept Request</title>
		<link>http://www.adnan-rashid.com/2008/09/28/asp-net-read-reciept-request/</link>
		<comments>http://www.adnan-rashid.com/2008/09/28/asp-net-read-reciept-request/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 04:00:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://blog.wtesolutions.com/?p=118</guid>
		<description><![CDATA[Here&#8217;s a quick tip. If you need to include a request for read receipt like Microsoft Outlook while sending mails through Asp.net, just add the Disposition-Notification-To Header to the MailMessage. The MailMessage class does not have a corresponding attribute and thus it has to be set through the Header. MailMessage mm = new MailMessage(fromAddress, toAddress); [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick tip. If you need to include a request for read receipt like Microsoft Outlook while sending mails through Asp.net, just add the <strong>Disposition-Notification-To</strong> Header to the MailMessage.</p>
<p>The MailMessage class does not have a corresponding attribute and thus it has to be set through the Header.</p>
<pre class="csharp">MailMessage mm = new MailMessage(fromAddress, toAddress);
mm.Subject = subject;
mm.Headers.Add("Disposition-Notification-To", sendReadReceiptToAddress);
</pre>
<p>Please keep in mind that this is only a request, and can be rejected/ignored by the Mail Client/User configuration.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.adnan-rashid.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.adnan-rashid.com/2008/09/28/asp-net-read-reciept-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic Handler &#8211; Session State</title>
		<link>http://www.adnan-rashid.com/2008/09/26/generic-handler-session-state/</link>
		<comments>http://www.adnan-rashid.com/2008/09/26/generic-handler-session-state/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 04:00:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://blog.wtesolutions.com/?p=120</guid>
		<description><![CDATA[In my current project I needed to access the Session state in a Generic Handler. To my dismay, i realized that the Session StateBag was null. The StateBag class is sealed and manages the Viewstate of the Asp.net server controls and pages. Upon discussion with my colleague, Mr. Hamed, we found the solution to my [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project I needed to access the Session state in a Generic Handler. To my dismay, i realized that the Session StateBag was null. The StateBag class is sealed and manages the Viewstate of the Asp.net server controls and pages.</p>
<p>Upon discussion with my colleague, Mr. Hamed, we found the solution to my problem. Using the <strong>IRequiresSessionState</strong> interface in System.Web.SessionState, we got access to Session state.</p>
<p>According to Microsoft &#8220;<em>Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.</em>&#8221;</p>
<p>Another option was to use the <strong>IReadOnlySessionState</strong> interface (Specifies that the target HTTP handler requires only read access to session-state values. This is a marker interface and has no methods.)</p>
<p>Needless to say, there is a performance increase in the latter case and if your requirement is only to read Session state, then that would be the right choice</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.adnan-rashid.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.adnan-rashid.com/2008/09/26/generic-handler-session-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encypting query string in Asp.Net</title>
		<link>http://www.adnan-rashid.com/2008/07/08/encypting-query-string-in-asp-net/</link>
		<comments>http://www.adnan-rashid.com/2008/07/08/encypting-query-string-in-asp-net/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 04:00:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://blog.wtesolutions.com/?p=18</guid>
		<description><![CDATA[When you pass information from one page to another, you are passing information that anybody can sniff. For example consider a scenario, in which you pass the customer id as a query string: http://www.yourapplication.com?customer_id=15 Now if somebody replaced 15 with say 10 or any other number, they can pull up other customer information. And that&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>When you pass information from one page to another, you are passing information that anybody can sniff. For example consider a scenario, in which you pass the customer id as a query string:</p>
<p>http://www.yourapplication.com?customer_id=15</p>
<p>Now if somebody replaced 15 with say 10 or any other number, they can pull up other customer information. And that&#8217;s bad for security.</p>
<p>One solution to this problem is to use encryption using a secret key. So lets use a hard-to-crack 8 byte key like <strong>$zm0!qp?</strong></p>
<p>To accomplish this here is a code snippet</p>
<pre class="csharp">using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Security.Cryptography;

public class Encryption64
{
    private byte[] key = {};
    private byte[] IV = {18, 52, 86, 120, 144, 171, 205, 239};

    public string Decrypt(string stringToDecrypt, string sEncryptionKey)
    {
		byte[] inputByteArray = new byte[stringToDecrypt.Length + 1];
		try
		{
			key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey, 8);
			DESCryptoServiceProvider des = new DESCryptoServiceProvider();
			inputByteArray = Convert.FromBase64String(stringToDecrypt);
			MemoryStream ms = new MemoryStream();
			CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
			cs.Write(inputByteArray, 0, inputByteArray.Length);
			cs.FlushFinalBlock();
			System.Text.Encoding encoding = System.Text.Encoding.UTF8;
			return encoding.GetString(ms.ToArray());
		}
		catch (Exception e)
		{
			return e.Message;
		}
    }

    public string Encrypt(string stringToEncrypt, string sEncryptionKey)
    {
		try
		{
			key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey, 8);
			DESCryptoServiceProvider des = new DESCryptoServiceProvider();
			byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
			MemoryStream ms = new MemoryStream();
			CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
			cs.Write(inputByteArray, 0, inputByteArray.Length);
			cs.FlushFinalBlock();
			return Convert.ToBase64String(ms.ToArray());
		}
		catch (Exception e)
		{
			return e.Message;
		}
    }
}
</pre>
<p><em>The end user will get to see a random text in the query string, something like</em></p>
<p><em>http://www.yourapplication.com/Receive.aspx?key=a2f5ckj?h79#8dd3</em></p>
<p><em>Remember stay secure stay safe.</em></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.adnan-rashid.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.adnan-rashid.com/2008/07/08/encypting-query-string-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asp.Net Reset Password</title>
		<link>http://www.adnan-rashid.com/2008/07/06/asp-net-reset-password/</link>
		<comments>http://www.adnan-rashid.com/2008/07/06/asp-net-reset-password/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 04:00:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://blog.wtesolutions.com/?p=5</guid>
		<description><![CDATA[If you are using Membership Provider in your ASP.net application, you might come across a scenario in which you need to have both Security Question and Answer feature and would also like to pro-grammatically reset the password for an account. So if you run the code string username = "user"; string password = "password"; MembershipUser [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using Membership Provider in your ASP.net application, you might come across a scenario in which you need to have both Security Question and Answer feature and would also like to pro-grammatically reset the password for an account.</p>
<p>So if you run the code</p>
<pre class="csharp">string username = "user";
string password = "password";
MembershipUser mu = Membership.GetUser(username);
mu.ChangePassword(mu.ResetPassword(), password);
</pre>
<p>You will get an error when you try to reset the password. A solution is to add another Membership provider having all the same settings as the default provider with only one exception:</p>
<pre class="xml">&lt;add name="NewMembershipProvider" requiresQuestionAndAnswer="false" ....../&gt;
</pre>
<p>For all Membership functions, you the default Membership provider will be used, but when you need to reset the password, you must reference the new Provider. Here&#8217;s a code excerpt to help you out:</p>
<pre class="csharp">string username = "user";
string password = "password";
MembershipUser mu = Membership.Providers["NewMembershipProvider"].GetUser(username, false);
mu.ChangePassword(mu.ResetPassword(), password);
</pre>
<p>So now your application can use both the Security feature to recover password and pro-grammatically Change/Reset the password when required.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.adnan-rashid.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.adnan-rashid.com/2008/07/06/asp-net-reset-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
