<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>C#, MS SQL,mySQL, Asp.net,Search-Engine-Optimization</title>
    <description>Tutorials on ASP, ASP.NET and JSP,Search-Engine-Optimization</description>
    <link>http://blog.nhachothue.net/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.6.1.0</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://blog.nhachothue.net/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://blog.nhachothue.net/syndication.axd</blogChannel:blink>
    <dc:creator>My name</dc:creator>
    <dc:title>C#, MS SQL,mySQL, Asp.net,Search-Engine-Optimization</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blognhachothue" /><feedburner:info uri="blognhachothue" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:thumbnail url="http://blog.nhachothue.net/pics/logo.gif" /><media:keywords>Tutorials,on,ASP,ASP,NET,and,JSP,Search,Engine,Optimization,Search</media:keywords><itunes:owner><itunes:email>tcdichvunhadat@gmail.com</itunes:email></itunes:owner><itunes:explicit>no</itunes:explicit><itunes:image href="http://blog.nhachothue.net/pics/logo.gif" /><itunes:keywords>Tutorials,on,ASP,ASP,NET,and,JSP,Search,Engine,Optimization,Search</itunes:keywords><itunes:subtitle>Tutorials on ASP, ASP.NET and JSP,Search-Engine-Optimization Search</itunes:subtitle><itunes:summary>Tutorials on ASP, ASP.NET and JSP,Search-Engine-Optimization&#xD;
Search</itunes:summary><item>
      <title>Phân Đoạn Bảng Theo Chiều Dọc</title>
      <description>&lt;p&gt;Khi l&amp;agrave;m việc với một bảng rộng gồm rất nhiều cột, trong đ&amp;oacute; chỉ c&amp;oacute; một  số cột được truy cập thường xuy&amp;ecirc;n, bạn c&amp;oacute; thể tăng hiệu năng cho c&amp;acirc;u  truy vấn tr&amp;ecirc;n c&amp;aacute;c cột n&amp;agrave;y bằng c&amp;aacute;ch t&amp;aacute;ch ch&amp;uacute;ng ra một bảng ri&amp;ecirc;ng. Khi đ&amp;oacute;  thay v&amp;igrave; c&amp;oacute; một bảng rộng như ban đầu th&amp;igrave; nay bạn c&amp;oacute; hai bảng: một bảng  gồm nh&amp;oacute;m c&amp;aacute;c cột được d&amp;ugrave;ng thường xuy&amp;ecirc;n, v&amp;agrave; một bảng gồm c&amp;aacute;c cột c&amp;ograve;n  lại. Cả hai bảng đều chứa cột kh&amp;oacute;a ch&amp;iacute;nh để giữ li&amp;ecirc;n hệ với nhau. L&amp;uacute;c  n&amp;agrave;y quan hệ giữa hai bảng l&amp;agrave; quan hệ 1-1. Trong trường hợp cần thiết,  bảng ban đầu c&amp;oacute; thể được t&amp;aacute;ch l&amp;agrave;m nhiều hơn hai bảng. Kỹ thuật n&amp;agrave;y gọi  l&amp;agrave; ph&amp;acirc;n đoạn bảng theo chiều dọc (vertical partitioning). N&amp;oacute;i n&amp;ocirc;m na l&amp;agrave;  bổ dọc bảng th&amp;agrave;nh nhiều mảnh.&lt;/p&gt;
&lt;p&gt;Trong c&amp;ocirc;ng việc t&amp;ocirc;i rất hay gặp những bảng c&amp;oacute; số lượng cột kh&amp;aacute; lớn.  V&amp;iacute; dụ trong một dự &amp;aacute;n t&amp;ocirc;i tham gia gần đ&amp;acirc;y c&amp;oacute; một bảng chứa 320 cột.  Nhưng sau khi khảo s&amp;aacute;t th&amp;igrave; ph&amp;aacute;t hiện ra c&amp;oacute; khoảng 30 cột l&amp;agrave; được truy  cập thường xuy&amp;ecirc;n hơn hẳn c&amp;aacute;c cột c&amp;ograve;n lại. Ch&amp;uacute;ng t&amp;ocirc;i đ&amp;atilde; d&amp;ugrave;ng kỹ thuật  ph&amp;acirc;n đoạn tr&amp;ecirc;n: chia th&amp;agrave;nh 2 bảng, một bảng chứa 30 cột được d&amp;ugrave;ng thường  xuy&amp;ecirc;n cộng với cột ID, bảng kia cũng chứa cột ID v&amp;agrave; c&amp;aacute;c cột c&amp;ograve;n lại.  Kết quả l&amp;agrave; hiệu năng tăng l&amp;ecirc;n đ&amp;aacute;ng kể: từ l&amp;uacute;c rất hay bị lỗi time-out do  thủ tục chạy qu&amp;aacute; l&amp;acirc;u (35-40s), đến nay đ&amp;atilde; ho&amp;agrave;n to&amp;agrave;n kh&amp;ocirc;ng bị nữa kể cả  khi server đang chịu tải nặng, với thời gian thực hiện thủ tục trung  b&amp;igrave;nh v&amp;agrave;o khoảng 10-12s.&lt;/p&gt;
&lt;p&gt;Vậy l&amp;yacute; do n&amp;agrave;o dẫn đến cải thiện về hiệu năng? Điều n&amp;agrave;y li&amp;ecirc;n quan đến  c&amp;aacute;ch tổ chức dữ liệu của bảng b&amp;ecirc;n trong SQL Server. SQL Server chia mỗi  bảng th&amp;agrave;nh c&amp;aacute;c &lt;em&gt;trang&lt;/em&gt; (page) c&amp;oacute; k&amp;iacute;ch thước đều nhau 8KB. C&amp;aacute;c bản  ghi được lưu nối tiếp nhau v&amp;agrave;o từng trang, đến khi đầy trang th&amp;igrave; lưu  tiếp sang trang mới. T&amp;ugrave;y theo k&amp;iacute;ch thước của bản ghi (bằng k&amp;iacute;ch thước  của c&amp;aacute;c cột cộng lại) m&amp;agrave; c&amp;oacute; bao nhi&amp;ecirc;u bản ghi được xếp vừa v&amp;agrave;o một  trang. Nếu k&amp;iacute;ch thước nhỏ sẽ c&amp;oacute; nhiều bản ghi được chứa trong một trang,  ngược lại nếu k&amp;iacute;ch thước lớn th&amp;igrave; mỗi trang sẽ chứa được &amp;iacute;t bản ghi.  Thậm ch&amp;iacute; nếu k&amp;iacute;ch thước n&amp;agrave;y vượt qu&amp;aacute; 8KB th&amp;igrave; v&amp;agrave;i trang mới chứa hết một  bản ghi (SQL Server 2000 kh&amp;ocirc;ng cho ph&amp;eacute;p điều n&amp;agrave;y n&amp;ecirc;n k&amp;iacute;ch thước bản ghi  tối đa được ph&amp;eacute;p tạo trong SQL Server 2000 chỉ l&amp;agrave; 8KB).&lt;/p&gt;
&lt;p&gt;Trang l&amp;agrave; đơn vị dữ liệu nhỏ nhất m&amp;agrave; hệ thống đọc từ ổ cứng. Kể cả khi  chỉ cần truy xuất một bản ghi th&amp;igrave; SQL Server cũng t&amp;igrave;m đến vả load cả  trang chứa n&amp;oacute; v&amp;agrave;o bộ nhớ. Do đ&amp;oacute; với bảng hẹp th&amp;igrave; c&amp;ugrave;ng một thao t&amp;aacute;c đọc  trang sẽ tải được nhiều bản ghi v&amp;agrave;o bộ nhớ hơn so với bảng rộng. Hay n&amp;oacute;i  c&amp;aacute;ch kh&amp;aacute;c, để đọc c&amp;ugrave;ng một số lượng bản ghi như nhau th&amp;igrave; bảng hẹp cần  đọc &amp;iacute;t trang hơn bảng rộng. V&amp;igrave; thế truy vấn tr&amp;ecirc;n bảng hẹp lu&amp;ocirc;n lu&amp;ocirc;n  nhanh hơn truy vấn tr&amp;ecirc;n bảng rộng.&lt;/p&gt;
&lt;p&gt;Trong v&amp;iacute; dụ sau, t&amp;ocirc;i c&amp;oacute; bảng BangBeo (bảng b&amp;eacute;o) gồm ba trường ID int,  txt1 char(10), txt2 char(8000). Nay t&amp;ocirc;i t&amp;aacute;ch bảng BangBeo th&amp;agrave;nh hai  bảng:&lt;br /&gt; &amp;middot; BangGay (bảng gầy) gồm ID v&amp;agrave; txt1&lt;br /&gt; &amp;middot; BangBeoPhu (bảng b&amp;eacute;o phụ) gồm ID v&amp;agrave; txt2&lt;/p&gt;
&lt;p&gt;T&amp;ocirc;i vẫn giữ lại bảng BangBeo ban đầu để so s&amp;aacute;nh&lt;/p&gt;
&lt;div class="wp_syntax"&gt;
&lt;div class="code"&gt;
&lt;pre class="tsql" style="font-family: monospace;"&gt;&lt;span style="color: #0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;TABLE&lt;/span&gt; BangBeo&lt;span style="color: #808080;"&gt;(&lt;/span&gt;ID &lt;span style="color: #0000ff;"&gt;INT&lt;/span&gt;, txt1 &lt;span style="color: #0000ff;"&gt;CHAR&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #000000;"&gt;10&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt;, txt2 &lt;span style="color: #0000ff;"&gt;CHAR&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #000000;"&gt;8000&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt; &lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;TABLE&lt;/span&gt; BangGay&lt;span style="color: #808080;"&gt;(&lt;/span&gt;ID &lt;span style="color: #0000ff;"&gt;INT&lt;/span&gt;, txt1 &lt;span style="color: #0000ff;"&gt;CHAR&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #000000;"&gt;10&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt; &lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;TABLE&lt;/span&gt; BangBeoPhu&lt;span style="color: #808080;"&gt;(&lt;/span&gt;ID &lt;span style="color: #0000ff;"&gt;INT&lt;/span&gt;, txt2 &lt;span style="color: #0000ff;"&gt;CHAR&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #000000;"&gt;8000&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt; &lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;DECLARE&lt;/span&gt; @i &lt;span style="color: #0000ff;"&gt;INT&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SET&lt;/span&gt; @i&lt;span style="color: #808080;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;WHILE&lt;/span&gt; @i&lt;span style="color: #808080;"&gt;&amp;amp;&lt;/span&gt;lt;&lt;span style="color: #808080;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;100&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;INSERT&lt;/span&gt; BangBeo &lt;span style="color: #808080;"&gt;(&lt;/span&gt;ID, txt1, txt2&lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SELECT&lt;/span&gt; @i, &lt;span style="color: #ff00ff;"&gt;REPLICATE&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;'a'&lt;/span&gt;,&lt;span style="color: #000000;"&gt;10&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt;, &lt;span style="color: #ff00ff;"&gt;REPLICATE&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;'a'&lt;/span&gt;,&lt;span style="color: #000000;"&gt;8000&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;INSERT&lt;/span&gt; BangGay &lt;span style="color: #808080;"&gt;(&lt;/span&gt;ID, txt1&lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SELECT&lt;/span&gt; @i, &lt;span style="color: #ff00ff;"&gt;REPLICATE&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;'a'&lt;/span&gt;,&lt;span style="color: #000000;"&gt;10&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;INSERT&lt;/span&gt; BangBeoPhu &lt;span style="color: #808080;"&gt;(&lt;/span&gt;ID, txt2&lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SELECT&lt;/span&gt; @i, &lt;span style="color: #ff00ff;"&gt;REPLICATE&lt;/span&gt;&lt;span style="color: #808080;"&gt;(&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;'a'&lt;/span&gt;,&lt;span style="color: #000000;"&gt;8000&lt;/span&gt;&lt;span style="color: #808080;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SET&lt;/span&gt; @i&lt;span style="color: #808080;"&gt;=&lt;/span&gt;@i&lt;span style="color: #808080;"&gt;+&lt;/span&gt;&lt;span style="color: #000000;"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;END&lt;/span&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;span style="color: #008000;"&gt;--ghi dữ liệu ra đĩa v&amp;agrave; x&amp;oacute;a cache&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;CHECKPOINT&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #008000;"&gt;-- hiện thống k&amp;ecirc; về v&amp;agrave;o ra đĩa&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;STATISTICS&lt;/span&gt; IO &lt;span style="color: #0000ff;"&gt;ON&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #008000;"&gt;-- x&amp;oacute;a cache để đảm bảo c&amp;ocirc;ng bằng khi so s&amp;aacute;nh&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;DBCC&lt;/span&gt; DROPCLEANBUFFERS &lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SELECT&lt;/span&gt; ID, txt1&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;FROM&lt;/span&gt; BangBeo&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #008000;"&gt;-- x&amp;oacute;a lại cache&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;DBCC&lt;/span&gt; DROPCLEANBUFFERS&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;SELECT&lt;/span&gt; ID, txt1&lt;br /&gt;&lt;span style="color: #0000ff;"&gt;FROM&lt;/span&gt; BangGay&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Mặc d&amp;ugrave; hai c&amp;acirc;u lệnh trả về c&amp;ugrave;ng một kết quả, nhưng phương &amp;aacute;n thực thi  cho thấy c&amp;acirc;u lệnh tr&amp;ecirc;n bảng gầy chỉ chiếm một phần nhỏ chi ph&amp;iacute; so với  c&amp;acirc;u lệnh tr&amp;ecirc;n bảng b&amp;eacute;o:&lt;br /&gt; &lt;img class="aligncenter size-full wp-image-2307" title="vertical-partition" src="http://www.sqlviet.com/blog/wp-content/uploads/2010/11/vertical-partition.jpg" alt="" width="541" height="530" /&gt;&lt;/p&gt;
&lt;p&gt;Trong v&amp;iacute; dụ tr&amp;ecirc;n, bảng b&amp;eacute;o c&amp;oacute; k&amp;iacute;ch thước bản ghi xấp xỉ 8KB, do đ&amp;oacute;  mỗi trang chứa được một bản ghi, tổng cộng bảng với 100 bản ghi sẽ chiếm  100 trang. C&amp;ograve;n bảng gầy c&amp;oacute; k&amp;iacute;ch thước vẻn vẹn 14 byte (INT 4 byte v&amp;agrave;  CHAR 10 byte) &amp;ndash; ch&amp;iacute;nh x&amp;aacute;c ra th&amp;igrave; c&amp;ograve;n th&amp;ecirc;m một số byte header. V&amp;igrave; thế  to&amp;agrave;n bộ bảng với 100 bản ghi chiếm chưa hết một trang. Như vậy mặc d&amp;ugrave;  trả về c&amp;ugrave;ng kết quả nhưng c&amp;acirc;u truy vấn tr&amp;ecirc;n bảng b&amp;eacute;o cần đọc tới 100  trang, c&amp;ograve;n c&amp;acirc;u lệnh tr&amp;ecirc;n bảng gầy chỉ cần đọc c&amp;oacute; 1 trang. Kết quả thống  k&amp;ecirc; I/O cũng cho thấy điều n&amp;agrave;y (ch&amp;uacute; &amp;yacute; c&amp;aacute;c con số t&amp;ocirc; đậm):&lt;/p&gt;
&lt;p&gt;Bảng b&amp;eacute;o:&lt;/p&gt;
&lt;p style="font-family: courier; text-align: left;"&gt;(100 row(s) affected)&lt;br /&gt; Table &amp;lsquo;BangBeo&amp;rsquo;. Scan count 1, logical reads &lt;strong&gt;100&lt;/strong&gt;, physical reads &lt;strong&gt;10&lt;/strong&gt;, read-ahead reads &lt;strong&gt;100&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Bảng gầy:&lt;/p&gt;
&lt;p style="font-family: courier; text-align: left;"&gt;(100 row(s) affected)&lt;br /&gt; Table &amp;lsquo;BangGay&amp;rsquo;. Scan count 1, logical reads &lt;strong&gt;1&lt;/strong&gt;, physical reads &lt;strong&gt;1&lt;/strong&gt;, read-ahead reads &lt;strong&gt;0&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Một v&amp;agrave;i lưu &amp;yacute;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Kỹ thuật ph&amp;acirc;n đoạn bảng theo chiều dọc như tr&amp;igrave;nh b&amp;agrave;y ở tr&amp;ecirc;n kh&amp;ocirc;ng  được hỗ trợ bởi Microsoft, theo nghĩa n&amp;oacute; kh&amp;ocirc;ng trong suốt đối với b&amp;ecirc;n  ngo&amp;agrave;i v&amp;agrave; c&amp;aacute;c bảng được ph&amp;acirc;n đoạn trở th&amp;agrave;nh c&amp;aacute;c bảng biệt lập (kh&amp;ocirc;ng  giống với ph&amp;acirc;n đoạn theo chiều ngang khi bảng vẫn hiện ra l&amp;agrave; một bảng  duy nhất). Việc t&amp;aacute;ch th&amp;agrave;nh c&amp;aacute;c bảng ri&amp;ecirc;ng như tr&amp;ecirc;n kh&amp;ocirc;ng nằm ngo&amp;agrave;i mục  đ&amp;iacute;ch n&amp;acirc;ng cao hiệu năng cho c&amp;acirc;u truy vấn tr&amp;ecirc;n một số cột nhất định. V&amp;igrave;  thế n&amp;oacute; chỉ c&amp;oacute; &amp;yacute; nghĩa khi bạn x&amp;aacute;c định được một tập c&amp;aacute;c cột được truy  vấn thường xuy&amp;ecirc;n hơn c&amp;aacute;c cột c&amp;ograve;n lại. Bạn cũng kh&amp;ocirc;ng phải c&amp;oacute; bảng rộng  tới 300 cột mới cần đến ph&amp;acirc;n đoạn. Kể cả với bảng hẹp hơn nhưng số cột  được truy vấn nhiều lần chỉ l&amp;agrave; một phần nhỏ trong tổng số tất cả c&amp;aacute;c  cột, bạn sẽ thấy lợi &amp;iacute;ch của việc ph&amp;acirc;n đoạn.&lt;/p&gt;
&lt;p&gt;Kỹ thuật ph&amp;acirc;n đoạn n&amp;agrave;y cũng k&amp;eacute;o theo một v&amp;agrave;i rắc rối khi viết code:&lt;/p&gt;
&lt;p&gt;Đối với lệnh SELECT, bạn phải nhớ c&amp;aacute;c cột n&amp;agrave;o nằm ở bảng n&amp;agrave;o để viết  c&amp;acirc;u lệnh cho đ&amp;uacute;ng,  v&amp;igrave; c&amp;aacute;c cột giờ kh&amp;ocirc;ng nằm chung trong một bảng nữa.  Bạn c&amp;oacute; thể tạo một view gom cả hai bảng v&amp;agrave; truy vấn qua view n&amp;agrave;y, nhưng  như thế sẽ l&amp;agrave;m mất đi t&amp;aacute;c dụng về hiệu năng, v&amp;igrave; khi JOIN th&amp;igrave; cả hai bảng  sẽ lu&amp;ocirc;n được truy xuất v&amp;agrave; số trang cần đọc kh&amp;ocirc;ng giảm đi t&amp;iacute; n&amp;agrave;o. Khi c&amp;oacute;  thay đổi về thiết kế, chẳng hạn cần di chuyển cột từ bảng n&amp;agrave;y sang bảng  kia, bạn phải quay lại sửa lại c&amp;acirc;u lệnh cũ.&lt;/p&gt;
&lt;p&gt;Đối với c&amp;aacute;c lệnh DELETE/INSERT/UPDATE, bạn lu&amp;ocirc;n nhớ cần thực hiện  tr&amp;ecirc;n cả hai bảng. Bạn c&amp;oacute; thể thực hiện c&amp;acirc;u lệnh qua view, v&amp;agrave; ở b&amp;ecirc;n dưới  view tạo một trigger loại INSTEAD OF trong đ&amp;oacute; thực hiện thao t&amp;aacute;c tr&amp;ecirc;n cả  hai bảng&lt;/p&gt;
&lt;p style="text-align: right;"&gt;nguồn sqlviet&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/NepsEd1Aa-c" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/NepsEd1Aa-c/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/Phan-c490oan-Bang-Theo-Chieu-Doc.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=4091a180-4fd3-4a36-8892-c956d66a3cbc</guid>
      <pubDate>Mon, 07 Mar 2011 04:49:00 +1400</pubDate>
      <category>MS SQL</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=4091a180-4fd3-4a36-8892-c956d66a3cbc</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=4091a180-4fd3-4a36-8892-c956d66a3cbc</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/Phan-c490oan-Bang-Theo-Chieu-Doc.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=4091a180-4fd3-4a36-8892-c956d66a3cbc</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=4091a180-4fd3-4a36-8892-c956d66a3cbc</feedburner:origLink></item>
    <item>
      <title>ASP.NET - Password Strength Indicator using jQuery and XML</title>
      <description>&lt;table class="articleViewer" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Last week, I had the opportunity to help implement and integrate a strong password policy to the legacy web application developed using ASP technology. The solution I proposed was to use jQuery to display the password strength meter to help users create strong password. Then one of my colleagues had asked "Do we have to modify the client-side script, code behind and password policy page if the client decided to alter the password policy?" The answer is "no", thanks to jQuery, the client-side script and code behind can share the same XML file. The password policy information is stored to an XML file and the client-side script and code behind are using the information in the XML file to perform the password strength validation.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I found several fine jQuery plug-in to display the user's password strength but I prefer to have something somewhat similar to the ASP.NET AJAX PasswordStrength control. After spending some time doing research, I am able to find all the necessary resources and assemble the jQuery plug-in to achieve the goal. Listed below are the features of the plug-in and I have put together a demo, everyone are welcome to download it.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;1.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Display password strength indicator in text and progress bar meter.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;2.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;The password policy, bar color and width are stored in the XML file and consume by the client-side and server side&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;3.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Use XSLT to transform the password policy XML file into HTML.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 1&lt;/p&gt;
&lt;p class="MsoNormal" style="text-align: center;"&gt;&lt;img id="Picture 1" src="http://aspalliance.com/ArticleFiles/2043/image001.gif" border="0" alt="" width="551" height="328" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure&lt;span class="Bold"&gt; 2&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="text-align: center;"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/2043/image002.gif" border="0" alt="" width="550" height="324" /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page2" class="pageTitle"&gt;&amp;nbsp; &lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Shown below is the content of the sample application. If you want to test the Classic ASP code, deploy the application to your IIS Web Server. The local ASP.NET Development Web Server does not support Classic ASP.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure&lt;span class="Bold"&gt; 3&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="text-align: center;"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/2043/image003.gif" border="0" alt="" width="279" height="309" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Default.aspx &amp;ndash; sample code in ASP.NET c# with MasterPage&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Default.aspx2 &amp;ndash; sample code in ASP.NET c# without MasterPage&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Password_strength_Indicator.asp &amp;ndash; sample code in Classic ASP&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;jQuery_Password_Strength_Indicator.htm &amp;ndash; sample code in HTML&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;PasswordPolicy.xml &amp;ndash; contains password policy information&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Password.xslt &amp;ndash; to transform PasswordPoclicy.xml file into HTML format&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;jQuery.password-strength.js &amp;ndash;this is the&amp;nbsp; plug-in I have created&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Download latest jQuery library from &lt;a href="http://jquery.com/"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page3" class="pageTitle"&gt;The Password Strength Indicator Plugin&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;In this section, I'll touch base briefly with the contents in the &lt;span class="Italic"&gt;jQuery.password-strength.js&lt;/span&gt; file. The code is very straight forward and comments are included. There is a jQuery AJAX request to read the XML file and populate the local variables based on the data in the XML file. If you are unsure of the relative URL, I would recommend using absolute URL to your XML file. The &lt;span class="Italic"&gt;getStrengthInfo()&lt;/span&gt; function contains the logic to check the password strength and return appropriate message based on user input. The password strength meter bar and text position are relative to the Textbox position. Shown below is the code in the &lt;span class="Italic"&gt;jQuery.password-strength.js&lt;/span&gt; file.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing&lt;span class="Bold"&gt; 1&lt;/span&gt;&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;(function($)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;password_Strength&amp;nbsp;=&amp;nbsp;new&amp;nbsp;function()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//return&amp;nbsp;count&amp;nbsp;that&amp;nbsp;match&amp;nbsp;the&amp;nbsp;regular expression&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.countRegExp&amp;nbsp;=&amp;nbsp;function(passwordVal, regx)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;match&amp;nbsp;=&amp;nbsp;passwordVal.match(regx);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;match&amp;nbsp;?&amp;nbsp;match.length&amp;nbsp;:&amp;nbsp;0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.getStrengthInfo&amp;nbsp;= function(passwordVal)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;len&amp;nbsp;=&amp;nbsp;passwordVal.length;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;pStrength&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;//password&amp;nbsp;strength&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;msg&amp;nbsp;=&amp;nbsp;"",&amp;nbsp;inValidChars&amp;nbsp;= "";&amp;nbsp;//message&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//get&amp;nbsp;special&amp;nbsp;characters&amp;nbsp;from&amp;nbsp;xml&amp;nbsp;file&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;allowableSpecilaChars&amp;nbsp;=&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new&amp;nbsp;RegExp("["&amp;nbsp;+ password_settings.specialChars&amp;nbsp;+&amp;nbsp;"]",&amp;nbsp;"g")&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;nums&amp;nbsp;= this.countRegExp(passwordVal,&amp;nbsp;/\d/g),&amp;nbsp;//numbers&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lowers&amp;nbsp;= this.countRegExp(passwordVal,&amp;nbsp;/[a-z]/g),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;uppers&amp;nbsp;= this.countRegExp(passwordVal,&amp;nbsp;/[A-Z]/g),&amp;nbsp;//upper&amp;nbsp;case&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;specials&amp;nbsp;= this.countRegExp(passwordVal,&amp;nbsp;allowableSpecilaChars),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//special&amp;nbsp;characters&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;spaces&amp;nbsp;= this.countRegExp(passwordVal,&amp;nbsp;/\s/g);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//check&amp;nbsp;for&amp;nbsp;invalid&amp;nbsp;characters&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;inValidChars&amp;nbsp;= passwordVal.replace(/[a-z]/gi,&amp;nbsp;"")&amp;nbsp;+&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;inValidChars.replace(/\d/g, "");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;inValidChars&amp;nbsp;= inValidChars.replace(/\d/g,&amp;nbsp;"");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;inValidChars&amp;nbsp;= inValidChars.replace(allowableSpecilaChars,&amp;nbsp;"");&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//check&amp;nbsp;space&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(spaces&amp;nbsp;&amp;gt;&amp;nbsp;0)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;"No&amp;nbsp;spaces!";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//invalid&amp;nbsp;characters&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(inValidChars&amp;nbsp;!==&amp;nbsp;'')&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;"Invalid&amp;nbsp;character: "&amp;nbsp;+&amp;nbsp;inValidChars;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//max&amp;nbsp;length&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(len&amp;nbsp;&amp;gt; password_settings.maxLength)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;"Password&amp;nbsp;too long!";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//GET&amp;nbsp;NUMBER&amp;nbsp;OF&amp;nbsp;CHARACTERS&amp;nbsp;left&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;((specials&amp;nbsp;+&amp;nbsp;uppers&amp;nbsp;+&amp;nbsp;nums&amp;nbsp;+ lowers)&amp;nbsp;&amp;lt;&amp;nbsp;password_settings.minLength)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;+=&amp;nbsp;password_settings.minLength -&amp;nbsp;(specials&amp;nbsp;+&amp;nbsp;uppers&amp;nbsp;+&amp;nbsp;nums&amp;nbsp;+&amp;nbsp;lowers)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+&amp;nbsp;"&amp;nbsp;more&amp;nbsp;characters,&amp;nbsp;";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//at&amp;nbsp;the&amp;nbsp;"at&amp;nbsp;least"&amp;nbsp;at&amp;nbsp;the front&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(specials&amp;nbsp;==&amp;nbsp;0&amp;nbsp;||&amp;nbsp;uppers&amp;nbsp;==&amp;nbsp;0&amp;nbsp;|| nums&amp;nbsp;==&amp;nbsp;0&amp;nbsp;||&amp;nbsp;lowers&amp;nbsp;==&amp;nbsp;0)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;+=&amp;nbsp;"At&amp;nbsp;least&amp;nbsp;";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//GET&amp;nbsp;NUMBERS&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(nums&amp;nbsp;&amp;gt;= password_settings.numberLength)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nums&amp;nbsp;= password_settings.numberLength;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;+= (password_settings.numberLength&amp;nbsp;-&amp;nbsp;nums)&amp;nbsp;+&amp;nbsp;"&amp;nbsp;more&amp;nbsp;numbers,&amp;nbsp;";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//special&amp;nbsp;characters&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(specials&amp;nbsp;&amp;gt;= password_settings.specialLength)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;specials&amp;nbsp;= password_settings.specialLength&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;+= (password_settings.specialLength&amp;nbsp;-&amp;nbsp;specials)&amp;nbsp;+&amp;nbsp;"&amp;nbsp;more&amp;nbsp;symbol,&amp;nbsp;";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//upper&amp;nbsp;case&amp;nbsp;letter&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(uppers&amp;nbsp;&amp;gt;= password_settings.upperLength)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;uppers&amp;nbsp;=&amp;nbsp;password_settings.upperLength&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;+= (password_settings.upperLength&amp;nbsp;-&amp;nbsp;uppers)&amp;nbsp;+&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"&amp;nbsp;Upper&amp;nbsp;case&amp;nbsp;characters, ";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//strength&amp;nbsp;for&amp;nbsp;length&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;((len&amp;nbsp;-&amp;nbsp;(uppers&amp;nbsp;+&amp;nbsp;specials&amp;nbsp;+&amp;nbsp;nums)) &amp;gt;=&amp;nbsp;(password_settings.minLength&amp;nbsp;-&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.numberLength&amp;nbsp;- password_settings.specialLength&amp;nbsp;-&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.upperLength))&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pStrength&amp;nbsp;+= (password_settings.minLength&amp;nbsp;-&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.numberLength&amp;nbsp;- password_settings.specialLength&amp;nbsp;-&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.upperLength);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pStrength&amp;nbsp;+=&amp;nbsp;(len&amp;nbsp;-&amp;nbsp;(uppers&amp;nbsp;+ specials&amp;nbsp;+&amp;nbsp;nums));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//password&amp;nbsp;strength&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pStrength&amp;nbsp;+=&amp;nbsp;uppers&amp;nbsp;+&amp;nbsp;specials&amp;nbsp;+&amp;nbsp;nums;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//detect&amp;nbsp;missing&amp;nbsp;lower&amp;nbsp;case&amp;nbsp;character&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(lowers&amp;nbsp;===&amp;nbsp;0)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(pStrength&amp;nbsp;&amp;gt;&amp;nbsp;1)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pStrength&amp;nbsp;-=&amp;nbsp;1;&amp;nbsp;//Reduce&amp;nbsp;1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;+=&amp;nbsp;"1&amp;nbsp;lower&amp;nbsp;case character,&amp;nbsp;";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//strong&amp;nbsp;password&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(pStrength&amp;nbsp;== password_settings.minLength&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;lowers&amp;nbsp;&amp;gt;&amp;nbsp;0)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;=&amp;nbsp;"Strong password!";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;msg&amp;nbsp;+&amp;nbsp;';'&amp;nbsp;+&amp;nbsp;pStrength;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//default&amp;nbsp;setting&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;password_settings&amp;nbsp;=&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;minLength:&amp;nbsp;12,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;maxLength:&amp;nbsp;25,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;specialLength:&amp;nbsp;1,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;upperLength:&amp;nbsp;1,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numberLength:&amp;nbsp;1,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;barWidth:&amp;nbsp;200,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;barColor:&amp;nbsp;'Red',&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;specialChars:&amp;nbsp;'!@#$',&amp;nbsp;//allowable&amp;nbsp;special characters&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;metRequirement:&amp;nbsp;false,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;useMultipleColors:&amp;nbsp;0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//password&amp;nbsp;strength&amp;nbsp;plugin&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$.fn.password_strength&amp;nbsp;=&amp;nbsp;function(options)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//check&amp;nbsp;if&amp;nbsp;password&amp;nbsp;met&amp;nbsp;requirement&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.metReq&amp;nbsp;=&amp;nbsp;function()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return password_settings.metRequirement;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//read&amp;nbsp;password&amp;nbsp;setting&amp;nbsp;from&amp;nbsp;xml&amp;nbsp;file&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$.ajax({&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type:&amp;nbsp;"GET",&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url:&amp;nbsp;"PasswordPolicy.xml", //use&amp;nbsp;absolute&amp;nbsp;link&amp;nbsp;if&amp;nbsp;possible&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataType:&amp;nbsp;"xml",&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;success:&amp;nbsp;function(xml)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(xml).find('Password').each(function()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;_minLength&amp;nbsp;= $(this).find('minLength').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_maxLength&amp;nbsp;= $(this).find('maxLength').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_numsLength&amp;nbsp;= $(this).find('numsLength').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_upperLength&amp;nbsp;= $(this).find('upperLength').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_specialLength&amp;nbsp;= $(this).find('specialLength').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_barWidth&amp;nbsp;= $(this).find('barWidth').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_barColor&amp;nbsp;= $(this).find('barColor').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_specialChars&amp;nbsp;= $(this).find('specialChars').text(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_useMultipleColors&amp;nbsp;= $(this).find('useMultipleColors').text();&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//set&amp;nbsp;variables&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.minLength&amp;nbsp;= parseInt(_minLength);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.maxLength&amp;nbsp;= parseInt(_maxLength);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; password_settings.specialLength&amp;nbsp;=&amp;nbsp;parseInt(_specialLength);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.upperLength =&amp;nbsp;parseInt(_upperLength);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.numberLength =&amp;nbsp;parseInt(_numsLength);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.barWidth&amp;nbsp;= parseInt(_barWidth);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.barColor&amp;nbsp;= _barColor;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.specialChars =&amp;nbsp;_specialChars;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; password_settings.useMultipleColors&amp;nbsp;=&amp;nbsp;_useMultipleColors;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;this.each(function()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//bar&amp;nbsp;position&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;barLeftPos&amp;nbsp;=&amp;nbsp;$("[id$='" +&amp;nbsp;this.id&amp;nbsp;+&amp;nbsp;"']").position().left&amp;nbsp;+&amp;nbsp;$("[id$='"&amp;nbsp;+&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.id&amp;nbsp;+&amp;nbsp;"']").width();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;barTopPos&amp;nbsp;=&amp;nbsp;$("[id$='"&amp;nbsp;+ this.id&amp;nbsp;+&amp;nbsp;"']").position().top&amp;nbsp;+&amp;nbsp;$("[id$='"&amp;nbsp;+&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.id&amp;nbsp;+&amp;nbsp;"']").height();&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//password&amp;nbsp;indicator&amp;nbsp;text&amp;nbsp;container&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;container&amp;nbsp;= $('&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;span&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;span&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.css({&amp;nbsp;position:&amp;nbsp;'absolute',&amp;nbsp;top: barTopPos&amp;nbsp;-&amp;nbsp;6,&amp;nbsp;left:&amp;nbsp;barLeftPos&amp;nbsp;+&amp;nbsp;15,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'font-size':&amp;nbsp;'75%',&amp;nbsp;display: 'inline-block',&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;width:&amp;nbsp;password_settings.barWidth +&amp;nbsp;40&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//add&amp;nbsp;the&amp;nbsp;container&amp;nbsp;next&amp;nbsp;to&amp;nbsp;textbox&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(this).after(container);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//bar&amp;nbsp;border&amp;nbsp;and&amp;nbsp;indicator&amp;nbsp;div&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;passIndi&amp;nbsp;=&amp;nbsp;$('&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;div&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;id&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="PasswordStrengthBorder"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;div&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;div&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;id&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="PasswordStrengthBar"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;class&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="BarIndicator"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;div&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.css({&amp;nbsp;position:&amp;nbsp;'absolute',&amp;nbsp;display: 'none'&amp;nbsp;})&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.eq(0).css({&amp;nbsp;height:&amp;nbsp;3,&amp;nbsp;top:&amp;nbsp;barTopPos -&amp;nbsp;16,&amp;nbsp;left:&amp;nbsp;barLeftPos&amp;nbsp;+&amp;nbsp;15,&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'border-style':&amp;nbsp;'solid', 'border-width':&amp;nbsp;1,&amp;nbsp;padding:&amp;nbsp;2&amp;nbsp;}).end()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.eq(1).css({&amp;nbsp;height:&amp;nbsp;5,&amp;nbsp;top:&amp;nbsp;barTopPos -&amp;nbsp;14,&amp;nbsp;left:&amp;nbsp;barLeftPos&amp;nbsp;+&amp;nbsp;17&amp;nbsp;}).end()&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//set&amp;nbsp;max&amp;nbsp;length&amp;nbsp;of&amp;nbsp;textbox&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//$("[id$='"&amp;nbsp;+&amp;nbsp;this.id&amp;nbsp;+ "']").attr('maxLength',&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.maxLength);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//add&amp;nbsp;the&amp;nbsp;boder&amp;nbsp;and&amp;nbsp;div&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;container.before(passIndi);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(this).keyup(function()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;passwordVal&amp;nbsp;=&amp;nbsp;$(this).val(); //get&amp;nbsp;textbox&amp;nbsp;value&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//set&amp;nbsp;met&amp;nbsp;requirement&amp;nbsp;to&amp;nbsp;false&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.metRequirement&amp;nbsp;= false;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(passwordVal.length&amp;nbsp;&amp;gt;&amp;nbsp;0)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;msgNstrength&amp;nbsp;= password_Strength.getStrengthInfo(passwordVal);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;msgNstrength_array&amp;nbsp;= msgNstrength.split(";"),&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;strengthPercent&amp;nbsp;=&amp;nbsp;0,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;barWidth&amp;nbsp;= password_settings.barWidth,&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;backColor&amp;nbsp;= password_settings.barColor;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//calculate&amp;nbsp;the&amp;nbsp;bar&amp;nbsp;indicator length&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(msgNstrength_array.length &amp;gt;&amp;nbsp;1)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;strengthPercent&amp;nbsp;= (msgNstrength_array[1]&amp;nbsp;/&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password_settings.minLength) *&amp;nbsp;barWidth;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $("[id$='PasswordStrengthBorder']")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.css({&amp;nbsp;display:&amp;nbsp;'inline', width:&amp;nbsp;barWidth&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//use&amp;nbsp;multiple&amp;nbsp;colors&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (password_settings.useMultipleColors&amp;nbsp;===&amp;nbsp;"1")&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//first&amp;nbsp;33%&amp;nbsp;is&amp;nbsp;red&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(parseInt(strengthPercent) &amp;gt;=&amp;nbsp;0&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;amp;&amp;amp; parseInt(strengthPercent)&amp;nbsp;&amp;lt;=&amp;nbsp;(barWidth&amp;nbsp;*&amp;nbsp;.33))&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;backColor&amp;nbsp;= "red";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//33%&amp;nbsp;to&amp;nbsp;66%&amp;nbsp;is&amp;nbsp;blue&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;if (parseInt(strengthPercent)&amp;nbsp;&amp;gt;=&amp;nbsp;(barWidth&amp;nbsp;*&amp;nbsp;.33)&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;amp;&amp;amp; parseInt(strengthPercent)&amp;nbsp;&amp;lt;=&amp;nbsp;(barWidth&amp;nbsp;*&amp;nbsp;.67))&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;backColor&amp;nbsp;= "blue";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;backColor&amp;nbsp;= password_settings.barColor;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $("[id$='PasswordStrengthBar']").css({&amp;nbsp;display:&amp;nbsp;'inline',&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;width:&amp;nbsp;strengthPercent, 'background-color':&amp;nbsp;backColor&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//remove&amp;nbsp;last&amp;nbsp;"," character&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (msgNstrength_array[0].lastIndexOf(",")&amp;nbsp;!==&amp;nbsp;-1)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; container.text(msgNstrength_array[0].substring(0,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msgNstrength_array[0].length -&amp;nbsp;2));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; container.text(msgNstrength_array[0]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(strengthPercent&amp;nbsp;== barWidth)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; password_settings.metRequirement&amp;nbsp;=&amp;nbsp;true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;container.text('');&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $("[id$='PasswordStrengthBorder']").css("display", "none");&amp;nbsp;//hide&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $("[id$='PasswordStrengthBar']").css("display", "none");&amp;nbsp;//hide&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;br /&gt;})(jQuery);&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page4" class="pageTitle"&gt;Using the Code&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Include a Textbox control, jQuery library and the plug-in into the web page. Change the &lt;span class="Bold"&gt;txtPassword&lt;/span&gt; id to your desire id. Use this line of code "var myPlugin = $("[id$='txtPassword']").password_strength();" to call the plug-in. To check if the password met the password policy, call the metReq() function with this line of code " myPlugin.metReq()". Please refer to Listing 1 for full details. The jQuery $("[id$='txtPassword']") selector will work with ASP.NET server control, so don't bother using my 'txtPassword.ClientID'. The bar color, width and password policy information can be modify through the XML file.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 2&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;div&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;style&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="height:400px"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:label&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;runat&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="server"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;id&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="lblPassword"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;AssociatedControlId&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="txtPassword"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;Enter Password:&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:label&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:TextBox&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;ID&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="txtPassword"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;runat&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="server"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:TextBox&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;a&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;id&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="passwordPolicy"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;href&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="#"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;Password&amp;nbsp;policy&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;a&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:Button&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;ID&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="btnSubmit"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;runat&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="server"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;Text&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="Submit"&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;br&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:Label&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;ID&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="ResultLabel"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;runat&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="server"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;Text&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=""&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:Label&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;div&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;script&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;src&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="Script/jquery-1.4.4.min.js"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;type&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="text/javascript"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;script&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;script&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;src&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="Script/jquery.password-strength.js"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;type&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="text/javascript"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;script&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;script&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;type&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="text/javascript"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(document).ready(function()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;myPlugin&amp;nbsp;= $("[id$='txtPassword']").password_strength();&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $("[id$='btnSubmit']").click(function()&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;myPlugin.metReq();&amp;nbsp;//return true&amp;nbsp;or&amp;nbsp;false&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $("[id$='passwordPolicy']").click(function(event)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;width&amp;nbsp;=&amp;nbsp;350,&amp;nbsp;height&amp;nbsp;=&amp;nbsp;300,&amp;nbsp;left&amp;nbsp;= (screen.width&amp;nbsp;/&amp;nbsp;2)&amp;nbsp;-&amp;nbsp;(width&amp;nbsp;/&amp;nbsp;2),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;top&amp;nbsp;=&amp;nbsp;(screen.height&amp;nbsp;/&amp;nbsp;2)&amp;nbsp;-&amp;nbsp;(height&amp;nbsp;/ 2);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;window.open("PasswordPolicy.xml", 'Password_poplicy',&amp;nbsp;'width='&amp;nbsp;+&amp;nbsp;width&amp;nbsp;+&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;',height='&amp;nbsp;+&amp;nbsp;height&amp;nbsp;+&amp;nbsp;',left='&amp;nbsp;+&amp;nbsp;left +&amp;nbsp;',top='&amp;nbsp;+&amp;nbsp;top);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;event.preventDefault();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;script&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;We can use the XLST to display the contents of the P&lt;span class="Italic"&gt;asswordPolicy.xml&lt;/span&gt; or write code to extract its contents. I preferred to use XLST to avoid writing additional code. Displayed below is the password policy page. If you want to learn more on how to displaying XML with XSLT click on &lt;a href="http://www.w3schools.com/xsl/xsl_transformation.asp"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 4&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/2043/image004.gif" border="0" alt="" width="310" height="218" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page5" class="pageTitle"&gt;Code Behind or Server-Side Code&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;The regular expression that we are using is listed in listing 3. The numbers are adjustable and come from the XML file.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 3&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;(?=^.{12,25}$)(?=(?:.*?\d){2})(?=.*[a-z])(?=(?:.*?[A-&lt;br /&gt;Z]){2})(?=(?:.*?[!@#$%*()_+^&amp;amp;}{:;?.]){2})(?!.*\s)[0-9a-zA-Z!@#$%*()_+^&amp;amp;]*$&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Shown in listing 4 is the code to generate regular expression dynamically. So, tomorrow if your client told you to increase the required digit in the password policy, you don't have to search or create a new regular expression. All you have to do is change the setting in the P&lt;span class="Italic"&gt;asswordPolicy.xml&lt;/span&gt; file. You can verify the regular expression &lt;a href="http://regexlib.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 4&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;btnSubmit_Click(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;sender,&amp;nbsp;EventArgs&amp;nbsp;e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PasswordSetting&amp;nbsp;passwordSetting&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; Helper.GetPasswordSetting();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StringBuilder&amp;nbsp;sbPasswordRegx&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; StringBuilder(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;.Empty);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//min&amp;nbsp;and&amp;nbsp;max&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sbPasswordRegx.Append(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"(?=^.{"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;passwordSetting.MinLength&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;","&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;passwordSetting.MaxLength&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"}$)"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//numbers&amp;nbsp;length&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sbPasswordRegx.Append(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"(?=(?:.*?\d){"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;passwordSetting.NumsLength&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"})"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//a-z&amp;nbsp;characters&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sbPasswordRegx.Append(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"(?=.*[a-z])"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//A-Z&amp;nbsp;length&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sbPasswordRegx.Append(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"(?=(?:.*?[A-Z]){"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; passwordSetting.UpperLength&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"})"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//special&amp;nbsp;characters&amp;nbsp;length&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sbPasswordRegx.Append(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"(?=(?:.*?["&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;passwordSetting.SpecialChars&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"]){"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;passwordSetting.SpecialLength&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"})"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//(?!.*\s)&amp;nbsp;-&amp;nbsp;no&amp;nbsp;spaces&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//[0-9a-zA-Z!@#$%*()_+^&amp;amp;]&amp;nbsp;--&amp;nbsp;valid characters&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sbPasswordRegx.Append(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"(?!.*\s)[0-9a-zA-Z"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; passwordSetting.SpecialChars&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"]*$"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(Regex.IsMatch(txtPassword.Text, sbPasswordRegx.ToString()))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ResultLabel.Text&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Password confront&amp;nbsp;password&amp;nbsp;policy!"&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;else&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ResultLabel.Text&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Password does&amp;nbsp;not&amp;nbsp;confront&amp;nbsp;password&amp;nbsp;policy!"&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="SectionHeading"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page6" class="pageTitle"&gt;Display Different Colors in the Progress Bar&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;I have received several suggestions from the reader to have different colors in the progress bar meter. I tried to implement this with the least possible change to the existing code. The current implementation does not have a complex algorithm to assign different weights to the characters. Here's how I implemented it, please refer to listing 5 for full details.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;1.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;The colors is based on the password length&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;2.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;If the password length between 0 and 33 percent, display red color&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;3.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;If the password length between 33 and 67 percent, display blue color&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;4.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;If above 67 percent, display the color specified in the PasswordPolicy.xml file&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;I also added &lt;span class="Italic"&gt;useMultipleColors&lt;/span&gt; attribute to the &lt;span class="Italic"&gt;PasswordPolixy.xml&lt;/span&gt; to give users the option to enable or disable the multiple colors.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;&lt;span class="Bold"&gt;Listing 5&lt;/span&gt;&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//use&amp;nbsp;multiple&amp;nbsp;colors&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(password_settings.useMultipleColors&amp;nbsp;=== "1")&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//first&amp;nbsp;33%&amp;nbsp;is&amp;nbsp;red&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(parseInt(strengthPercent)&amp;nbsp;&amp;gt;=&amp;nbsp;0 &amp;amp;&amp;amp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parseInt(strengthPercent)&amp;nbsp;&amp;lt;= (barWidth&amp;nbsp;*&amp;nbsp;.33))&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;backColor&amp;nbsp;=&amp;nbsp;"red";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//33%&amp;nbsp;to&amp;nbsp;66%&amp;nbsp;is&amp;nbsp;blue&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;if&amp;nbsp;(parseInt(strengthPercent)&amp;nbsp;&amp;gt;= (barWidth&amp;nbsp;*&amp;nbsp;.33)&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parseInt(strengthPercent)&amp;nbsp;&amp;lt;= (barWidth&amp;nbsp;*&amp;nbsp;.67))&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;backColor&amp;nbsp;=&amp;nbsp;"blue";&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;backColor&amp;nbsp;=&amp;nbsp;password_settings.barColor;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/lfnYEB0Ogpg" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/lfnYEB0Ogpg/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/ASPNET-Password-Strength-Indicator-using-jQuery-and-XML.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=4f3154ac-ef62-4b3f-929b-c8021c8b7e32</guid>
      <pubDate>Thu, 10 Feb 2011 05:24:00 +1400</pubDate>
      <category>ASP.NET</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=4f3154ac-ef62-4b3f-929b-c8021c8b7e32</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=4f3154ac-ef62-4b3f-929b-c8021c8b7e32</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/ASPNET-Password-Strength-Indicator-using-jQuery-and-XML.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=4f3154ac-ef62-4b3f-929b-c8021c8b7e32</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=4f3154ac-ef62-4b3f-929b-c8021c8b7e32</feedburner:origLink></item>
    <item>
      <title>Understanding Code Access Security in .NET</title>
      <description>&lt;table class="articleViewer" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;In Microsoft .NET you have two types of security, Code Access Security and Role Based Security. In this article we will explore what the latter implies, how it can be used, etc. So, what is Code Access Security then? Code Access Security (CAS) is a security feature of .NET that enables the code that is to be executed to be properly verified and different levels of trust granted accordingly. It actually provides the flexibility to define what the code could perform and what not to perform. This article discusses CAS, the functions and benefits of CAS, permissions and permission sets.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page2" class="pageTitle"&gt;What is Code Access Security?&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Code Access Security (CAS) is a feature in .NET which imposes security on the code under execution based on that has created it, from where was it downloaded or copied and what are the evidences of the code. Evidences tell where the code is supposed to execute. So based on the evidence, permissions are set and these permissions are managed by policies. There are other definitions of CAS too.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;According to the MSDN, "Code access security allows code to be trusted to varying degrees depending on where the code originates and on other aspects of the code's identity. Code access security also enforces the varying levels of trust on code, which minimizes the amount of code that must be fully trusted in order to run. Using code access security can reduce the likelihood that your code can be misused by malicious or error-filled code. It can reduce your liability because you can specify the set of operations your code should be allowed to perform as well as the operations your code should never be allowed to perform. Code access security can also help minimize the damage that can result from security vulnerabilities in your code."&lt;/p&gt;
&lt;p class="MsoNormal"&gt;According to Wikipedia, "Code Access Security (CAS), in the Microsoft .NET Framework, is Microsoft's solution to prevent untrusted code from performing privileged actions. When the CLR loads an assembly it will obtain evidence for the assembly and use this to identify the code group that the assembly belongs to. A code group contains a permission set (one or more permissions). Code that performs a privileged action will perform a code access demand which will cause the CLR to walk up the call stack and examine the permission set granted to the assembly of each method in the call stack. The code groups and permission sets are determined by the administrator of the machine who defines the security policy."&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page3" class="pageTitle"&gt;Benefits&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;The benefits of CAS are many. Here is a list of the major benefits of CAS.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;It defines a set of permissions that would specify how the system resources should be accessed by verifying the demanded permissions with the one that is granted.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Permission sets defined are configured into code groups, through which an administrator can configure the security policy.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Provides a control over the resource acquisition by the code by strictly adhering to the permission sets configured.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Provides the code to demand if its callers have required permissions.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page4" class="pageTitle"&gt;How does it work?&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;The security system which is built into the CLR defines a permission set which could apply to a particular resource. To access a resource, the code needs to undergo authentication and authorization process. This is done by traversing through the code and tracking the identity beneath which is usually termed as stack walk.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In managed code, any permission demanded is verified by the CLR security manager. The CLR security manager walks through the call stack by mapping the permissions demanded and the permissions granted. A SecurityException is thrown if the permission demanded is not found in the call stack. So the actual permissions are checked depending on the evidences. So evidences provide information on where the code was actually executed. Below is the diagram (figure taken from MSDN Article) which depicts the mechanism based on which the identity is traced across all the referenced assemblies by performing a call stack.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 1&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image001.jpg" alt="" width="456" height="206" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;(Adapted from an article at MSDN)&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page5" class="pageTitle"&gt;What are Policies and Policy Levels?&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Policies represent the user role which could be categorized as: Application Domain Policy, User Policy, Machine Policy and Enterprise Policy. The purpose of each is defined below.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Enterprise Policy &amp;ndash; This policy is specified by the enterprise administrator. This would target to all managed code in an enterprise.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Machine Policy - This policy is specified by the enterprise administrator. This would target to all managed code in the local computer.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;User Policy - This policy is specified by the enterprise administrator or the user of the machine. &amp;nbsp;This would target to all managed code associated with the current user.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Application Domain Policy - The policy is specified by the enterprise administrator. This would target all managed code in an application.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;A policy is a configuration file which holds details on what the assembly is permitted to do depending upon the evidence collected. A common overlap of permission sets between various policies is termed as an Intersection. These policies are defined in a hierarchical structure and before applying permission all of the policies in the hierarchic should accept it.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page6" class="pageTitle"&gt;What is a Code Group?&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Policies are configured based on a hierarchy of code groups. Code groups are structured at every policy level. So if the evidence gathered matches with the membership of a code group within a policy level, the associated set of permissions is granted to the assembly. The MSDN defines the code; groups are defined as follows:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;"A code group is a logical grouping of code that has a specified condition for membership. Any code that meets the membership condition is included in the group. Code groups have associated permission sets that are evaluated during a policy grant."&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page7" class="pageTitle"&gt;Permission&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Permission defines the ability of an operation to have access on particular resources. They impose specific levels of authorization to a protected resource. The runtime security system defines permissions like File IO, Printing, Socket Access, Event Log, Web Access, User Interface and so forth.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;What are Permission Sets?&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Permission set is a collection of permissions which are used to modify the security policy for code groups. The CLR provides the following built-in permission sets.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Italic"&gt;Nothing &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Implies that the code cannot be executed.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Italic"&gt;Execution&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Implies that code does not have permission to access protected resources, but can execute.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Italic"&gt;Internet&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Implies that code downloaded from a location and has limited permissions.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Italic"&gt;LocalIntranet&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Implies that the code holds permissions defined in the default enterprise policy.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Italic"&gt;Everything&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Implies that the code has all permissions except to skip verification.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Italic"&gt;FullTrust&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Code has full access to all system resources.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page8" class="pageTitle"&gt;Using Code Access Security in .NET&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;In this section we will explore how we can use CAS from our applications programmatically. Here is a sample code.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 1&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;btnConnectDB_Click(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;sender, EventArgs&amp;nbsp;e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;DataSet&amp;nbsp;dsContact&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt;&amp;nbsp;DataSet();&lt;br /&gt;&amp;nbsp;&amp;nbsp;SqlConnection&amp;nbsp;dbConnection&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; SqlConnection(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Server=.;Database=Adventureworks;Trusted_Connection=true"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;SqlCommand&amp;nbsp;dbCommand&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; SqlCommand(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"SELECT&amp;nbsp;*&amp;nbsp;FROM&amp;nbsp;Person.Contact"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbConnection);&lt;br /&gt;&amp;nbsp;&amp;nbsp;dbConnection.Open();&lt;br /&gt;&amp;nbsp;&amp;nbsp;SqlDataAdapter&amp;nbsp;dataAdapter&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; SqlDataAdapter(dbCommand);&lt;br /&gt;&amp;nbsp;&amp;nbsp;dataAdapter.Fill(dsContact);&lt;br /&gt;&amp;nbsp;&amp;nbsp;dbConnection.Close();&lt;br /&gt;&amp;nbsp;&amp;nbsp;MessageBox.Show(String.Format(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"{0}&amp;nbsp;Rows fetched&amp;nbsp;from&amp;nbsp;the&amp;nbsp;database."&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dsContact.Tables[0].Rows.Count));&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;btnReadFile_Click(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;sender, EventArgs&amp;nbsp;e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;StreamReader&amp;nbsp;sr&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; File.OpenText(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"D:\Sample.txt"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;content&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;sr.ReadToEnd();&lt;br /&gt;&amp;nbsp;&amp;nbsp;MessageBox.Show(content);&lt;br /&gt;&amp;nbsp;&amp;nbsp;sr.Close();&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;btnWriteFile_Click(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;sender, EventArgs&amp;nbsp;e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;StreamWriter&amp;nbsp;sw&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; StreamWriter(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;@"D:\Sample.txt"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;sw.WriteLine(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Hello&amp;nbsp;World!"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;sw.Close();&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Refer to the code snippet given above. What we are trying to do is an attempt to connect to the database in the click event of the button btnConnectDB, and then we are trying to read and write in the subsequent buttons. Now you need to compile this project with a strong name and then configure the security permissions using the .NET Configuration Tool. In the section that follows we will explore how we can use the .NET Configuration Tool to configure security permissions.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page9" class="pageTitle"&gt;Using the Microsoft .NET Framework 2.0 Configuration Tool&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Go to Visual Studio command prompt and type mscorcfg.msc&amp;nbsp; &amp;lt;Enter&amp;gt;.&amp;nbsp; Refer to the screen shot below.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 2&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image002.jpg" alt="" width="501" height="570" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;When you click on the option "Microsoft .NET Framework 2.0Configuration," you should see the following dialog.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 3&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image003.jpg" alt="" width="662" height="481" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Right click on the Permission Sets and select New.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 4&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image004.jpg" alt="" width="662" height="479" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Now, enter a name for the permission set and click next.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 5&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image005.jpg" alt="" width="483" height="458" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;From the available permissions shown in the screen shot above, select one or more permissions and set the required attributes. In our case we will choose SQLClient, File IO, User Interface and Security. Refer to the screen shots below.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 6&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image006.jpg" alt="" width="662" height="480" /&gt;&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 7&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image007.jpg" alt="" width="662" height="479" /&gt;&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 8&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image008.jpg" alt="" width="662" height="479" /&gt;&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 9&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image009.jpg" alt="" width="662" height="479" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Observe that we have set permissions for all the selected permissions. Now, click on finish. You should be able to see the following screen.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 10&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image010.jpg" alt="" width="662" height="481" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Next, go to the code groups, right click on All_Code and select New.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 11&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image011.jpg" alt="" width="662" height="479" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Specify a new to the new code group as shown below.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 12&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image012.jpg" alt="" width="483" height="458" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Select the option "Strong Name" as the condition type. Remember that at this stage you should be ready to create a strong key and compiling your project with this key. Once that is done, click the Import button to import the assembly. You will notice that the public key is copied into the box. Refer to the screen shot given below.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 13&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image013.jpg" alt="" width="662" height="468" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Then you need to select a permission set from the lost of the permission sets. We shall select the one we had created earlier. Here is the screen shot that illustrates the same.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 14&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image014.jpg" alt="" width="483" height="458" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Once that is done, you need to select the first check box in the membership group. This is because permissions will be a union for more than one set of policies. By checking the first check box, we are saying to use only the permissions that we specified.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 15&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image015.jpg" alt="" width="406" height="432" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Now, when you try to execute your project, you will see the following exception. This exception is thrown because you do not have permission to access the SqlClient assemblies. Here is the screen shot that illustrates this.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 16&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image016.jpg" alt="" width="662" height="480" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Note that we have set the read permissions to the Sample.txt file, but not the write permissions to it. When you click on the next screen, here is the output that you will see.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 17&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1506/image017.jpg" alt="" width="662" height="480" /&gt;&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Reckoning of Permissions&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We have discussed the policy levels and code groups. But, how would the run time calculate the permissions when the code belongs to multiple policies or code groups in the same policy? The run time does it in the following manner.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Initially, the entire All_Code group and all its child code groups are checked for any matching permissions. As said, permissions are identified by evidences.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Then a union of permissions is performed for those identified in various groups.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The above procedure is repeated for each policy level and the outcome of permissions at each level are then intersected.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Requesting for Permissions&lt;/p&gt;
&lt;p class="MsoNormal"&gt;You might have encountered a time when you wished to check the permissions for an assembly before actually performing any operations. For instance, you might have a small windows application that reads configuration data from the UI and creates an XML file to store that information. But at the time of saving, the assembly might have not gotten any permission on the C:, and a security exception was thrown. To handle this, CAS provides three approaches which can be applied at the assembly level using declarative syntax.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;RequestMinimum&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;RequestOptional&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;RequestRefuse&lt;/p&gt;
&lt;p class="MsoNormal"&gt;RequestMinimum defines the permissions the code requires to execute. For example, the code below makes an attempt to write into a file. If the code does not have any permissions for writing then the assembly will not be loaded.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 2&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;using&lt;/span&gt;&amp;nbsp;System.IO;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;using&lt;/span&gt;&amp;nbsp;System.Security;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;using&lt;/span&gt;&amp;nbsp;System.Windows.Forms;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;using&lt;/span&gt;&amp;nbsp;System.Security.Permissions;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//&amp;nbsp;This&amp;nbsp;is&amp;nbsp;a&amp;nbsp;declarative&amp;nbsp;security&amp;nbsp;call&amp;nbsp;at assembly&amp;nbsp;level.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;[FileIOPermissionAttribute(SecurityAction.RequestRefuse, &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"C:"&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;namespace&lt;/span&gt;&amp;nbsp;DemoApp&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;class&lt;/span&gt;&amp;nbsp;MyClass&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//TODO:....&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;RequestOptional defines permissions that the code can use, but is not necessarily required to execute. In this case the assembly is loaded, but if the required permissions are not set then a security exception is thrown by the run time.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;RequestRefuse defines a set of permissions that you might never want to grant to the code even though the security policy allows the permissions. Suppose that you need to ensure that you want to read the files and not even accidentally write into those files, then you could use the following.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 3&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;[assembly:FileIOPermission(SecurityAction.RequestRefuse, Write="C:")]&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page10" class="pageTitle"&gt;Imperative versus Declarative Security&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;The code security can be implemented by either using the Declarative Security or the Imperative Security. Let us now understand how these two differ.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Declarative Security&lt;/p&gt;
&lt;p class="MsoNormal"&gt;This is accomplished by placing security attributes at the assembly level, class level or member level. The attribute indicates the request type, overrides and demands. Each permission object has a state data, and this needs to be initialized to use that permission. Also, each permission has an attribute to which the type of security action, which is an enumeration called SecurityAction, is passed to the attribute. In the example below, all the members of the class are restricted accessing the "Program Files" folder.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 4&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;[FileIOPermissionAttribute(SecurityAction.RequestRefuse, &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"C:\Program&amp;nbsp;Files"&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;class&lt;/span&gt;&amp;nbsp;RestrictPF&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;RestrictPF()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//security&amp;nbsp;call&amp;nbsp;protects&amp;nbsp;the&amp;nbsp;constructor.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;SomeMethod()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//security&amp;nbsp;call&amp;nbsp;also&amp;nbsp;protects&amp;nbsp;this method.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;If you want to restrict the permission on the assembly level, you can use the following.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 5&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;[assembly: FileIOPermissionAttribute(SecurityAction.RequestRefuse,&amp;nbsp;"C:\Program Files")]&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;If you want to restrict any registry access from the assembly level, you can use the following.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 6&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;[assembly:&amp;nbsp;RegistryPermissionAttribute(SecurityAction.RequestRefuse, Unrestricted&amp;nbsp;=&amp;nbsp;true)]&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;So even though the code runs in an environment that allows access to the registry or perform FileIO operations, the assembly will not be granted any kind of permissions.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Imperative Security&lt;/p&gt;
&lt;p class="MsoNormal"&gt;This kind of security could be used to perform demands and overrides. This helps in situations where you want to check the permissions at runtime. However, this kind of security cannot be used to perform requests. In imperative syntax, a new instance of the security permission object needs to be created before calling. Also, you need to initialize the permission set to invoke a security object. A permission set consists of a group of permissions; initializing a permission group provides a means to perform assert calls on multiple permissions in one method. For this purpose you could use the NamedPermissionSet and PermissionSet classes for grouping of permissions. You can then call the required method to invoke the appropriate security call.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 7&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;class&lt;/span&gt;&amp;nbsp;RestrictPF&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;RestrictPF(){}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;SomeMethod()&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//Here&amp;nbsp;the&amp;nbsp;FileIOPermissionAttribute&amp;nbsp;is demanded&amp;nbsp;using&amp;nbsp;the&amp;nbsp;imperative&amp;nbsp;syntax.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//Method&amp;nbsp;is&amp;nbsp;protected&amp;nbsp;by&amp;nbsp;security&amp;nbsp;call.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FileIOPermissionAttribute&amp;nbsp;flsIOPerm&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; FileIOPermissionAttribute();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;flsIOPerm.Demand();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;SomeOtherMethod()&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//Method&amp;nbsp;not&amp;nbsp;protected&amp;nbsp;by&amp;nbsp;security&amp;nbsp;call.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/gV2Mph2TV_M" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/gV2Mph2TV_M/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/Understanding-Code-Access-Security-in-NET.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=b306be12-acb8-432e-a20b-b7c1c9d81e21</guid>
      <pubDate>Sat, 29 Jan 2011 06:17:00 +1400</pubDate>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>Programming Language</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=b306be12-acb8-432e-a20b-b7c1c9d81e21</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=b306be12-acb8-432e-a20b-b7c1c9d81e21</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/Understanding-Code-Access-Security-in-NET.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=b306be12-acb8-432e-a20b-b7c1c9d81e21</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=b306be12-acb8-432e-a20b-b7c1c9d81e21</feedburner:origLink></item>
    <item>
      <title>Developing Custom Controls - Part 1</title>
      <description>&lt;table class="articleViewer" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Server controls are meant for eliminating redundant code and boosting productivity. They make development tasks easier by hiding their internal details and providing ready to use packaged functionality. There are many controls shipped with ASP.NET that shorten development effort, but there are always opportunities for us to build our own controls to reduce even more development effort. Many times business scenarios create the need of custom controls to simplify development solutions.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;If you want some reusable functionality in a single application or for few developers and it can be achieved from combining existing web controls then user controls can be a good choice. But when you want to make a piece of functionality reusable and redistributable then custom controls will be the best solution. You can extend some control or make one from scratch or combine multiple ones as per your need. This activity will let you get into the things and will add confidence for bringing novelty and uniqueness into your projects. Most importantly, you will become adept at intrinsic details of the architecture of the dozens of standard controls shipped with ASP.NET. The purpose of these controls is to achieve a different functionality (from the existing server control), a totally new functionality, or a combined functionality of several other existing or new server controls.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page2" class="pageTitle"&gt;Need of a Custom Control&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;&amp;nbsp;&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;In this article we will examine the need, types and the architecture of custom controls. First of al, you must be aware of your requirement whether or not it really requires a custom control irrespective of the fact you will be able to develop it or not. It might be that the case that can be best handled with user controls. To analyze the need of a custom control you must know what it lacks, if there is some similar control already in the standards controls toolkit. Sometimes you may decide to go for an entirely new control if none of the controls have any functionality that you could inherit. The need of custom controls can be better understood if we learn a little about their types.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page3" class="pageTitle"&gt;Types of Custom Controls&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Literally speaking, "a control is custom for user if it fulfills a requirement that can&amp;rsquo;t be satiated by any standard control." The term custom control becomes vague sometime for the user when there is a parallel term of user controls which are also custom controls in nature, but are created differently. I would like to put light on this ambiguity and will try to resolve it. Yet before this, it is more important to know the types of custom controls and their place in the hierarchy of controls.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It is important to know that all controls are server controls i.e. they run at server and are rendered into the appropriate HTML controls at the client's browser.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We can make two major level categories of server controls.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Just In Time (JIT) Compiled&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Pre Compiled&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;JIT compiled controls are those controls that are embeddable in the source of aspx page and are compiled as per demand i.e. just in time. These controls, directly or indirectly, are inherited from System.Web.UI.WebControls.WebControl or System.Web.UI.Control which let them expose properties and provide events. They are compiled when the page gets compiled by the Framework. The following are the main types of JIT compiled controls.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;HTML server controls&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Web server controls&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;Validation controls&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;User controls&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Let us take a look on these controls one by one.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;HTML Server Controls&lt;/p&gt;
&lt;p class="MsoNormal"&gt;HTML controls support an additional property of &amp;ldquo;runat.&amp;rdquo; If this set is to &amp;ldquo;server,&amp;rdquo; it runs at server and is accessible in the code behind. Therefore, it is said to be an HTML Server control. Since these controls require less UI support, they are inherited from System.Web.UI.Control.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Web Server Controls&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Web server controls are all standard server side controls that are shipped with ASP.NET. They include simple controls such as Panel and as rich as GridView. The basic purpose of these controls is to minimize the effort required for designing pages or building tools/controls that automatically generate user interface. These controls hide details of their internal working and make the task easier and less erroneous for developers. It is important to know that these controls inherit one of these two classes.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Bold"&gt;System.Web.UI.Control &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;It defines the properties, methods, and events that are common to all web server controls, for example methods and events needed handle the execution lifecycle. This does not support any UI specific feature. The controls that require no UI support inherit this class, such as ASP.NET controls including Literal, Repeater, PlaceHolder and XML.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;or&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span class="Bold"&gt;System.Web.UI.WebControls.WebControl&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The WebControl class inherits Control class and exposes additional properties and provides methods for UI support. A control that renders some UI should be inherited from WebControl. It is the class which provides UI-related properties such as BackColor, ForeColor, Font, Height, Width, etc. All ASP.NET controls except aforementioned controls inherit this class.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Validation Controls&lt;/p&gt;
&lt;p class="MsoNormal"&gt;These controls are used for validation of the input of other controls of a page/user control. These controls can perform client side, server side or both types of validation. Validation controls inherits the BaseValidator class that implements IValidator interface and inherits Label class, thus they inherit System.Web.UI.WebControls.WebControl indirectly.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;User Controls&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Lastly let us have a look at user controls and know how they are different from custom controls. User controls are custom in nature by purpose not by architecture. Development and design-wise they have nothing common with custom controls. They are closer to an aspx page than a custom control. This may be a bit misleading yet we have to take them entirely separate. Their architecture and way of working is entirely different the only thing that is common is they both can fulfill custom needs of a user.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The following are the important differences between a user control and a custom control from all aspects.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page4" class="pageTitle"&gt;User Control vs. Custom Control&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control inherits System.Web.UI.UserControl class with class&amp;nbsp;hierarchy (bottom up) MyUserControl&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; UserControl&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; TemplateControl&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; Control&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; Object. Whereas a custom controls inherits System.Web.UI.Control or System.Web.UI.WebControls.WebControl class with class&amp;nbsp;hierarchy (bottom up) either MyCustomControl&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; Control&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; Object OR MyCustomControl&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; WebControl&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; Control&lt;span style="font-family: Wingdings;"&gt;&amp;agrave;&lt;/span&gt; Object.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control has extension .ascx and is JIT compiled, while a custom control is in the form of dynamic linked library (.ddl), thus pre-compiled.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control must encapsulate functionality of other web server control(s) through dragging and dropping in design mode. A custom control does not have any design editor. It may or may not inherit functionality of other standard control(s). It can be an entirely new one.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control is easy to create because it can be designed like a page is designed i.e. they have design editor and code behind simultaneously while a custom control does not have design editor so is harder to create.&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control requires registration and instantiation per page and resides on a page as an object and is compiled along with the page. It is not in pre-compiled form whereas a custom control (newly created or extended) is a separate and pre-compiled component.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control cannot be registered with Global Assembly Cache (GAC) while a custom control can be registered with GAC, thus giving an advantage of being a framework wide component. A custom control is more reusable because you do not need a separate copy of it for each application; it can automatically be loaded be from the GAC.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control is compiled as a part of the same page class while a custom control is compiled as a separate, distinct class. Moreover, any client side logic (html, JavaScript, DOM etc.) is also written programmatically in case of Custom controls.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control cannot provide the level of richness that a custom control can provide. It is because custom control&amp;rsquo;s class is not bound with any design. Here you can take the leverage of the flexibility and richness of .NET programming model; you can expose properties, override functions of the base class and also register complex client side logic in the class.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control may fulfill your need if you are working on a single web application while a custom control is the best choice especially when you want to make your controls redistributable, more reusable and make it a Visual Studio IDE aware component.&lt;/p&gt;
&lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;&amp;middot;&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;A user control can use a custom control, but vice versa is not possible.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page5" class="pageTitle"&gt;Custom Server Controls&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Now getting specific to custom controls they are Pre Compiled in nature. As mentioned earlier, there three types of custom control with respect of their requirement and way of developing them. Types of custom controls are Extended, Composite and Fully Custom. It is important to note that these categories are not hard and fast. There can be a control that can fall into all three categories simultaneously. It can be a totally new, composite and may have its constituent controls extended, composite or new ones. We will explore them separately. Let us take a look on each of these types with respect to their requirement and development method.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Extended&lt;/p&gt;
&lt;p class="MsoNormal"&gt;If there is a standard web server control that meets most of our requirements and you want it to do few more tasks, then you will go for extended custom control. You will add a few more properties to achieve the desired tasks. For this purpose you extend the existing web server control, letting the new one inherit the full functionality set and behavior of the existing control and adding the required ones.&amp;nbsp;&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Composite&lt;/p&gt;
&lt;p class="MsoNormal"&gt;You build a new control combining functionality of two or more existing controls. Suppose you want to build a control named PrimeTester; you would be required to include three standard web server controls to make it accomplished. It will combine functionality of a Textbox, Button and Label. A TextBox for input, a Button to test if it is prime and a Label to show the test result. Many standard web server controls shipped with ASP.NET are of composite nature. A simpler example is ASP.NET CheckBox control. Its gets rendered into two html controls. Say there is the following ASP.NET Checkbox control on the page.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 1&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;asp:CheckBox&amp;nbsp;&amp;nbsp;id=&amp;rdquo;checkbox1&amp;rdquo;&amp;nbsp;runat=&amp;rdquo;server&amp;rdquo;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Text=&amp;rdquo;This&amp;nbsp;is&amp;nbsp;simple&amp;nbsp;composite&amp;nbsp;control&amp;rdquo;&amp;nbsp;&amp;hellip; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;If you see the source of the page in the browser, you will notice that it has been rendered into these controls.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 2&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;input&amp;nbsp;type=&amp;rdquo;checkbox&amp;rdquo;&amp;nbsp;id=checkbox1&amp;hellip;/&amp;gt;&amp;nbsp;and &lt;br /&gt;&amp;lt;Label&amp;nbsp;for=&amp;rdquo;&amp;nbsp;checkbox1&amp;rdquo;&amp;gt;&amp;nbsp;This&amp;nbsp;is&amp;nbsp;simple composite&amp;nbsp;control&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;Label&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Since the html control &amp;ldquo;input&amp;rdquo; of type checkbox  cannot support storing and displaying the contents of Text property of  the ASP.NET Checkbox control, the html Label control has been added to keep record of the text of the Checkbox. The &amp;ldquo;for&amp;rdquo; property of the html label control keeps the ID of  the associated Checkbox.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We will see composite custom controls in detail with a working example of a new composite control in Part II of the article.&lt;/p&gt;
&lt;p class="SectionHeading"&gt;Fully Custom&lt;/p&gt;
&lt;p class="MsoNormal"&gt;When none of the standard web server controls fulfills your requirements, what you want is entirely different from the functionality of any existing server control. You need to go for an entirely new one that neither extends any of the standard web server controls nor combines functionality of an exiting control. Based on the functionality of a fully custom control, it might have to implement one or more of the interfaces System.Web.UI.INamingContainer, &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.ipostbackdatahandler%28VS.71%29.aspx"&gt;&lt;span style="color: windowtext; text-decoration: none;"&gt;System.Web.UI.IPostBackDataHandler&lt;/span&gt;&lt;/a&gt; or &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.ipostbackeventhandler%28VS.71%29.aspx"&gt;&lt;span style="color: windowtext; text-decoration: none;"&gt;System.Web.UI.IPostBackEventHandler&lt;/span&gt;&lt;/a&gt;.&amp;nbsp; We will look on fully custom controls in detail with a working example of a new fully custom control in Part II of the article.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page6" class="pageTitle"&gt;Building an Extended Custom Control &lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Extending an existing server control is an interesting and a simple job most of the time. I have chosen TextBox control for this purpose. Let us first analyze our need of building an extended TextBox control as we do not want to extend it just for the sake of an example! This analysis can be divided into two parts finding deficiencies to make up and suggesting enhancements that are useful. I emphasize on the analysis so that we can extend it meaningfully and purposefully making it a really useful member of our control tool kit. With inclusion of these properties in our control you will also be able to learn how a custom control can emit HTML and JavaScript as per required.&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;There is a deficiency that really becomes problematic for developers; when the TextMode of the TextBox is set to Multiline, the MaxLength property stops working. We will discuss why it cannot support this.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;While focusing on enhancements there are several which can be very useful, for example providing a support for entering cased input uppercase or lowercase, numeric, and alphanumeric. A textbox can also be self validating, these enhancements can add a good worth to it. So after a little analysis, we are able to figure out what we want to overcome and what we want to add in our new control.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Our new Textbox, ExtendedTextBox, will have the following features.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;1.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;It supports a cased input by providing TextCaseMode property.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;2.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;It supports an input mode for numeric and alphanumeric input by providing InputMode property.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;3.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;It supports MaxLength property when TextMode is set to MultiLine also.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;4.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;It provides built in required field validation by providing IsRequired property.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Now getting specific to the implementation, the following are the steps to accomplish all this.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;5.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;First, create a new project of Web Control Library. Please note that VB and Visual C# in Standard Edition do not support the Web Control Library template. It is only available in the professional edition.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;6.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Give the class some suitable name, in our case ExtendedTextBox, and extend it from its base i.e. TextBox as shown below.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 3&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;[Description(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Extended&amp;nbsp;TextBox&amp;nbsp;v1.0 (Developed&amp;nbsp;by&amp;nbsp;Mahr&amp;nbsp;G.&amp;nbsp;Mohyuddin)"&lt;/span&gt;)]&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;[DefaultProperty(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Text"&lt;/span&gt;)]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;[ToolboxData(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;lt;{0}:ExtendedTextBox runat=server&amp;gt;&amp;lt;/{0}:ExtendedTextBox1&amp;gt;"&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;class&lt;/span&gt;&amp;nbsp;ExtendedTextBox&amp;nbsp;: System.Web.UI.WebControls.TextBox&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;...&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;You can see the class has been adorned with some attributes, Description, DefaultProperty and ToolboxData. Description attribute keeps the description of the control that is displayed on bringing the ouse over it in the tool box. DefaultProperty is used to bring the given property to focus when the property window of a control is displayed. ToolBoxData is a mandatory attribute that is used to define the look of control declaration in aspx markup when it is dropped on the page. It ensures that the control is given the class name; otherwise it will flag an error. You can also add more attributes like DefaultEvent, which add declaration of the specified event in the code behind when a control is double clicked. ToolBoxItem specifies whether the control should be visible or not; when it is set to True the control is visible and vice versa. ToolBoxBiitmap sepecifies the bitmap image that should be used as the icon for the control and finally ToolBoxItemFilter attribute specifies the filter Visual Studio 2005 uses to determine whether the control should be enabled or disabled for a specific designer.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Now, add properties that we need to expose to let the world use features we are going to provide. This includes TextCaseMode, InputMode, IsRequired, and ErrorMessage. Definition of all properties is similar. For instance, TextCaseMode sets the case of the text to be entered. It can be Uppercase, Lowercase or NotSet. We will need an enumeration for this purpose. The following code snippet shows the definition of TextCaseMode property.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 4&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;[Description(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Sets&amp;nbsp;the&amp;nbsp;case&amp;nbsp;of&amp;nbsp;the&amp;nbsp;text entered"&lt;/span&gt;)][Category(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Behavior"&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;][DefaultValue(TextCaseMode.NotSet)]&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;TextCaseMode&amp;nbsp;TextCaseMode&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;get&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;o&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"TextCaseMode"&lt;/span&gt;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;return&lt;/span&gt;&amp;nbsp;(o&amp;nbsp;!&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;&amp;nbsp;?&amp;nbsp;(TextCaseMode)o: TextCaseMode.NotSet);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;set&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"TextCaseMode"&lt;/span&gt;]&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The property has been adorned with three attributes: Description, Category and DefaultValue. Use of Description is quite evident. Category attribute takes the name of the category in the property pane of the control in Visual Studio IDE. All properties of a control are organized in Accessibly, Appearance, Behavior, Data, Layout and Misc categories. We want the new property TextCaseMode to be displayed in Behavior category.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Another important attribute is DefaultValue which sets a default value,; the specified one, is shown when the no value is set by user. In our case we want the text case mode not to be set by default. Therefore, NotSet has been provided as the default value.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;This property is of type TextCaseMode enum that has been defined. A property that is of type enum is shown in the form of Dropdownlist in the control property pane.&amp;nbsp;&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 1&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1526/image001.jpg" border="0" alt="" width="330" height="570" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The new properties added to the control have been encircled. You can see that the name with description (provided in Description attribute) of the selected property appears on the bottom of the pane.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;A value of property is set and retrieved in/from ViewState having name of property of the property as key, since ASP.NET controls save their state through ViewState. Similarly, a custom control should also save its state. In other words, the value of properties exposed by a custom control should be retained on postbacks. It can be possible only if we set the value of a property in ViewState and get from it as shown above. The following code snippet shows the definition of TextCaseMode and InputMode enums.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 5&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;enum&lt;/span&gt;&amp;nbsp;TextCaseMode&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;UpperCase,&amp;nbsp;LowerCase,&amp;nbsp;NotSet&lt;br /&gt;}&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;enum&lt;/span&gt;&amp;nbsp;InputMode&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;Alphanumeric,&amp;nbsp;Numeric,&amp;nbsp;NotSet&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Similarly, define other properties InputMode, IsRequired and ErrorMessage. In short, InputMode property is used to set the mode the text being entered that can either be Numeric, Alphanumeric or NotSet. The enum used has been defined in Listing 3.&amp;nbsp; IsRequired property when set to true makes input in the textbox mandatory and stops all postback until some value is entered. It shows the error, in tooltip, given in ErrorMessage property when the mouse comes over it.&amp;nbsp; The following code snippet shows the definition of the rest of properties.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 6&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;[Description(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Sets&amp;nbsp;input mode"&lt;/span&gt;)][Category(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Behavior"&lt;/span&gt;)][DefaultValue&lt;br /&gt;&amp;nbsp;&amp;nbsp;(InputMode.NotSet)]&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;InputMode&amp;nbsp;InputMode&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;get&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;o&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"InputMode"&lt;/span&gt;];&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;return&lt;/span&gt;&amp;nbsp;o&amp;nbsp;!&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;&amp;nbsp;?&amp;nbsp;(InputMode)o: InputMode.NotSet;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;set&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"InputMode"&lt;/span&gt;]&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;[Description(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Mandates&amp;nbsp;if&amp;nbsp;the&amp;nbsp;text&amp;nbsp;is required"&lt;/span&gt;)][Category(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Behavior"&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;][DefaultValue(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;false&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;bool&lt;/span&gt;&amp;nbsp;IsRequired&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;get&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;o&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"IsRequired"&lt;/span&gt;];&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;return&lt;/span&gt;&amp;nbsp;o&amp;nbsp;==&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;&amp;nbsp;?&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;false&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;set&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"IsRequired"&lt;/span&gt;]&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;[Description(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Displays&amp;nbsp;messages&amp;nbsp;if&amp;nbsp;textbox input&amp;nbsp;is&amp;nbsp;required"&lt;/span&gt;)][Category(&lt;br /&gt;&amp;nbsp; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Behavior"&lt;/span&gt;)][DefaultValue(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;""&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;ErrorMessage&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;get&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;o&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"ErrorMessage"&lt;/span&gt;];&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;return&lt;/span&gt;&amp;nbsp;o&amp;nbsp;!&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;&amp;nbsp;?&amp;nbsp;(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;)o:&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;""&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;set&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ViewState[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"ErrorMessage"&lt;/span&gt;]&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Since all the features of the control should work on client side we have client side script events to handle this. We have to write JavaScript code that will be emitted by the control as per demanded by the user who specify them through properties.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;For this purpose we have to override PreRender event of the control so that our new control will be able to add the JavaScript logic before completing the rendering of the control.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We will add this code in the overridden PreRender event of the control as the following exhibit shows.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 7&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;protected&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;override&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;OnPreRender(EventArgs&amp;nbsp;e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;base&lt;/span&gt;.OnPreRender(e);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;alphaNumeric&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"function alphaNumeric(textBox){&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"if(/[^0-9A-Za-z]/.test(textBox.value)){&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.value=textBox.value.replace(/([^0-9A-Za-z])/g,'');&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.title&amp;nbsp;=&amp;nbsp;'';&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"} "&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;nbsp;}"&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;numeric&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"function&amp;nbsp;numeric (textBox){&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"if(/[^0-9a-z]/.test(textBox.value)){ "&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.value= textBox.value.replace(/([^0-9])/g,'');&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.title&amp;nbsp;=&amp;nbsp;'';&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"} "&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;nbsp;}"&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;...&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The code snippet shows that we have called PreRender event of the base class i.e. TextBox and then declared and initialized two string members alphaNumeric and numeric that define javascript methods for respective functionality. I will explain one of them as an example and all upcoming JavasSript code will be quite similar. Please note that we have not registered them yet, that will be done later. We have defined alphaNumeric method that takes the textbox object as parameter and tests it on a regular expression (regExp) object by calling test method. If it is true then call the replace method on the result, that replaces any undesired input char with empty string; it uses again the same regExp object with a global search qualifier g to search the input. You may have noticed that before closing the body of the methods, we have cleared the title property of the textbox which shows an error message as the tooltip when IsRequired is set to True. So on any input we should clear the tooltip.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Likewise, define other javascript methods for UppCase,LoweCase, MaxLength and IsRequired features and set the respective string variables so that later could be registered on demand.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 8&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;hellip;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;upperCase&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"function upperCase(textBox){&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"if(/[^0-9A-Z]/.test(textBox.value)){ "&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.value=textBox.value.toUpperCase().replace(/([^0-9A-Z])/g,''); "&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.title&amp;nbsp;=&amp;nbsp;'';&amp;nbsp;"&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"}&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"}"&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;lowerCase&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"function lowerCase(textBox){&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"if(/[^0-9A-Z]/.test(textBox.value)){ "&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.value=textBox.value.toLowerCase().replace(/([^0-9A-Z])/g,''); "&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"textBox.title&amp;nbsp;=&amp;nbsp;'';&amp;nbsp;"&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"}&amp;nbsp;"&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"}"&lt;/span&gt;;&lt;br /&gt;&amp;hellip;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;UpperCase and lowerCase methods have similar logic, the only change is the input is upper/lower cased by calling string class&amp;rsquo;s method toUpperCase() and toLowerCase(). Now it is time to register them on the basis of the property set by the user. The user may form any combination of the properties TextCaseMode (UpperCase,Lowercase,NotSet), InputMode (Numeic,AlphaNUmeric,NotSet). For this purpose we have to define another method which will call these methods depending upon the properties&amp;rsquo; values. The following code snippet shows this.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 9&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;hellip;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;cleintScript&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"function extendedTextBox_PropertyChange(xTextBox){"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//&amp;nbsp;method&amp;nbsp;body&amp;nbsp;starts&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.InputMode&amp;nbsp;==&amp;nbsp;InputMode.Numeric)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.GetType(), &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"numeric"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numeric,&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;cleintScript&amp;nbsp;+=&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"numeric(xTextBox); "&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.InputMode&amp;nbsp;==&amp;nbsp;InputMode.Alphanumeric)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.GetType(), &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"alphaNumeric"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;alphaNumeric,&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;cleintScript&amp;nbsp;+=&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"alphaNumeric(xTextBox); "&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.TextCaseMode&amp;nbsp;==&amp;nbsp;TextCaseMode.UpperCase)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.GetType(),&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"upperCase"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;upperCase,&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;cleintScript&amp;nbsp;+=&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"upperCase(xTextBox); "&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.TextCaseMode&amp;nbsp;==&amp;nbsp;TextCaseMode.LowerCase)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.GetType(), &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"lowerCase"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lowerCase,&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;cleintScript&amp;nbsp;+=&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"lowerCase(xTextBox); "&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&lt;br /&gt;cleintScript&amp;nbsp;+=&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;nbsp;}"&lt;/span&gt;;&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//&amp;nbsp;end&amp;nbsp;of&amp;nbsp;method body&lt;/span&gt;&lt;br /&gt;&amp;hellip;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;We have defined a string variable &amp;ldquo;clientScript&amp;rdquo; initialized with the method name; the forthcoming code registers script for a particular method and appends its script, i.e being added in the body of the main work horse method extendedTextBox_PropertyChange. At the end, append the string that closes the body of the method. Now we have to register extendedTextBox_PropertyChange method. The following code snippet not only registers it, but also adds it in the attributes collection of the control for onpropertychange event. We can also use onkeypress event, but using this will notice little elapse in uppercasing and lowercasing the input character.&amp;nbsp;&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 10&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;hellip;&lt;br /&gt;Page.ClientScript.RegisterClientScriptBlock(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.GetType(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"cleintScript"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cleintScript,&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;);&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.Attributes.Add(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"onpropertychange"&lt;/span&gt;, &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"extendedTextBox_&amp;nbsp;PropertyChange&amp;nbsp;(this);"&lt;/span&gt;);&lt;br /&gt;&amp;hellip;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Next, we have defined checkMaxLength method that makes MaxLength property of the textbox working when its TextMode is set to MultiLine. In TextBox control this problem arises when TextBox is MultiLine because in this case it is rendered into &amp;ldquo;TextArea&amp;rdquo; html control (&amp;lt;textarea id="ExtendedTextBox1" /&amp;gt;) instead of&amp;nbsp; &amp;ldquo;input control with type text&amp;rdquo; (&amp;lt;input name="ExtendedTextBox1" type="text" id="ExtendedTextBox1). It is important to know that TextArea control does not support MaxLengh property. Therefore, when we set TextMode property to MultiLine, the MaxLength property stops working. To resolve this problem we have to write some client side logic and make part of the control as shown in the following listing.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 11&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;hellip;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;checkMaxLength&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"function checkMaxLength(textBox)&amp;nbsp;{"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;nbsp;if(textBox)&amp;nbsp;{&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;nbsp;return&amp;nbsp;(&amp;nbsp;textBox.value.length &amp;lt;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.MaxLength&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;");&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;nbsp;}&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"}&amp;nbsp;"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.TextMode&amp;nbsp;==&amp;nbsp;TextBoxMode.MultiLine)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Page.ClientScript.RegisterClientScriptBlock(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.GetType(),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"checkLength"&lt;/span&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;checkMaxLength,&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.Attributes.Add(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"onkeypress"&lt;/span&gt;, &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"return&amp;nbsp;checkMaxLength(this);"&lt;/span&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;It checks and returns true if the length of input is less than or equal to the value of MaxLength property and false if vice versa. Then we have to register it as usual and add in the attributes collection of the control for onkeypress event.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Now, there is another very important feature added in the new textbox control. It mandates the input if specified using the IsRequired property. The implementation of this is simple, we have to handle form&amp;rsquo;s client side onSubmit event as shown in following code.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 12&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;hellip;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.IsRequired&amp;nbsp;==&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;true&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.Page.Form.Attributes.Add(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"onSubmit"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"if("&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.ClientID&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;".value==''){"&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.ClientID&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;".title&amp;nbsp;=&amp;nbsp;'"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.ErrorMessage&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"';"&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"return&amp;nbsp;false;}&amp;nbsp;"&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"else{&amp;nbsp;"&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;this&lt;/span&gt;.ClientID&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt; &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;".title&amp;nbsp;=&amp;nbsp;'';&amp;nbsp;"&lt;/span&gt;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;+&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"&amp;nbsp;return&amp;nbsp;true;}"&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;}&amp;nbsp;&lt;span style="color: green; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;//&amp;nbsp;end&amp;nbsp;of&amp;nbsp;PreRender&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Instead of making a separate method, the handler for onSubmit has been added directly in the attributes collection of the control. It checks if IsRequired property is set to True then sets the title property (used for tooltip) of control with the error message given by the user in ErrorMessage property and return false, otherwise clears the title property and return true i.e. allows postbacks.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;When IsRequired property is set to True, it performs the required field validation, stops all postabacks and shows the error message in tooltip when the mouse is brought over the control. The Following figure shows this.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/xJqhwuc5XQM" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/xJqhwuc5XQM/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/Developing-Custom-Controls-Part-1.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=a470b085-566b-4318-8265-95552c815745</guid>
      <pubDate>Sat, 29 Jan 2011 06:14:00 +1400</pubDate>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>Programming Language</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=a470b085-566b-4318-8265-95552c815745</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=a470b085-566b-4318-8265-95552c815745</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/Developing-Custom-Controls-Part-1.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=a470b085-566b-4318-8265-95552c815745</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=a470b085-566b-4318-8265-95552c815745</feedburner:origLink></item>
    <item>
      <title>Role Based Forms Authentication in ASP.NET 2.0</title>
      <description>&lt;p&gt;&lt;span id="abstractLabel"&gt;Using Role based forms authentication, we can  restrict users of the site to accessing certain resource if they are not  part of a particular role. In this article, Satheesh demonstrates how  to build sites with this type of authentication. He provides a short  overview of various Login Controls and Providers and then discusses a  scenario with detailed explanation of various aspects of the sample  application with screenshots and source code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;table class="articleViewer" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Any ASP.NET site we develop will always have an authentication module unless and until there is nothing private on the site or something we explicitly know as being unnecessary. For instance, a simple public content site will not require an authentication module. Depending on the nature of the application we can decide on the type of authentication we are going to provide for our site. Meaning, if it is going to be an intranet web application, we can very well utilize the windows authentication by making use of the availability of user information in the AD, thus preventing a separate user information storage private to our application. Still, role mapping to the users has to be stored privately for the application. If our application is an internet application then the best choice is to use Forms Authentication. This article will explore the implementation forms authentication with roles in ASP.NET 2.0.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;From 1.x days, the implementation of forms authentication in ASP.NET is not that complicated. But the actual drawbacks are in those days ASP.NET itself does not have that many controls that aid in implementing forms authentication easily. Also, if we have role based forms authentication then we should go for our custom code for validating a resource access. With the introduction of 2.0 we have a handful of controls that help in implementing role based forms authentication very easily with the primary support of Providers in ASP.NET 2.0.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page2" class="pageTitle"&gt;Who Process the FormsAuthentication?&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Forms authentication is processed by a HTTP module called FormsAuthenticationModule which takes part in regular ASP.NET page processing.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page3" class="pageTitle"&gt;Login Controls and Providers&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;As I said earlier, ASP.NET 2.0 is packed with set of new controls called Login controls through which we can implement forms authentication with less effort. This section will take us through how best to use these Login controls in our projects. By default, Login controls will use the default membership provider and role provider which will have their own database schema. So, it is not advisable to use this controls as it is because enterprise applications itself will have its own database schema and architecture. The solution for this problem is to develop our own custom provider or our own custom code that solves our application specific requirements. However, we can still use some of the login controls, like LoginView, LoginName and LoginStatus, in our applications. In this article I will explain our subject matter with a custom implemented login form without using any login control on it. Also, we will have a look on how to use some of the login controls effectively with role based forms authentication. Moving forward, I will explain a sample scenario where we can use role based forms authentication and will use the same scenario throughout this article for easy understanding.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page4" class="pageTitle"&gt;Scenario&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Consider we are creating a content management system where users can login and post their contents. The posted contents will be moderated by the administrator of the site. Meaning, Administrator can either approve or reject the content posted by the user. The posted content can be viewed by anyone once it is approved by the admin. In this scenario we can have 2 roles defined, namely Admin and Publishers. The sample application attached with this article uses the same scenario explained in this article.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page5" class="pageTitle"&gt;Application Structure&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;&amp;nbsp;&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Our application will have two folders called Admin and Publisher as shown in the figure below (Figure 1 &amp;ndash; Sample Application Solution). Admin folder will have all the ASPX pages that are put together to form the Admin module while the Publisher folder will have all the ASPX pages for Publisher module.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 1 &amp;ndash; Sample Application Solution&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1619/image001.jpg" alt="" width="174" height="222" /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page6" class="pageTitle"&gt;Configuring Forms Authentication&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;As we all know, this is done in Web.config by changing the value of &amp;lt;authentication&amp;gt; tag.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 1&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authentication&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;mode&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="Forms"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;forms&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;loginUrl&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="Login.aspx"&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;name&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=".ASPXAUTH"&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;protection&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="All"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;forms&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authentication&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The default timeout for forms authentication is 30 minutes. It indicates that 30 minutes of inactivity on the application will cause timeout expiration and the user will be prompted to the login page. Any hit to the site after login will reset this clock to 30 minutes again starting from that time. If we want to override this setting then we can include this in the above &amp;lt;forms&amp;gt; tag. See MSDN for a full list of attributes that can be specified in this tag.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;After configuring forms authentication we need to configure the authorization part of the Web.Config.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 2&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authorization&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;allow&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;users&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="*"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authorization&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The above setting says it will allow all the users because the posted content should be viewed by anyone as I said in the Scenario section. The next section will explain the configuration settings to restrict users accessing the pages in Admin and Publisher folders.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page7" class="pageTitle"&gt;Controlling Access to Roles&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;This is done by &amp;lt;Location&amp;gt; tag in Web.Config file.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 3&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;location&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;path&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="ADMIN"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;system.web&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authorization&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;allow&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;roles&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="ADMIN"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;deny&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;users&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="*"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authorization&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;location&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;location&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;path&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="Publishers"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;system.web&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authorization&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;allow&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;roles&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="PUBLISHER,ADMIN"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;deny&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;users&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="*"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;authorization&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;location&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The above setting will restrict users trying to access the Admin section and Publisher section until they are part of that role and allow users who are already part of the roles.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page8" class="pageTitle"&gt;Constructing Login Form&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Construct a login form that has a textbox for entering user ID and password, and a button for login with an optional Remember me checkbox.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;On Login button click do the following steps.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;1.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Create Forms Authentication ticket.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 4 &amp;ndash; FormsAuthentication ticket syntax&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;FormsAuthenticationTicket&amp;nbsp;ticket&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; FormsAuthenticationTicket(&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;int&lt;/span&gt;&amp;nbsp;version,&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;userName,&lt;br /&gt;DateTime&amp;nbsp;CreationTime,&lt;br /&gt;DateTime&amp;nbsp;Expiration,&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;bool&lt;/span&gt;&amp;nbsp;IsPersistent,&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;UserData,&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;CookiePath);&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoListNumber"&gt;2.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;User&amp;rsquo;s role information can be specified in UserData in the above argument list.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;3.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Encrypt the above created ticket through following method in FormsAuthentication class.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 5 - Encrypt Ticket&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;Encrypt(FormsAuthenticationTicket&amp;nbsp;ticket);&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoListNumber"&gt;4.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;It returns a string containing an encrypted forms-authentication ticket suitable for use in an HTTP cookie.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;5.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Create the cookie with the encrypted.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;6.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Add the created cookie to the response object.&lt;/p&gt;
&lt;p class="MsoListNumber"&gt;7.&lt;span style="font: 7pt &amp;quot;Times New Roman&amp;quot;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;The below code Listing 6 shows the implementation of the above steps.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 6 - Login Event&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;protected&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt;&amp;nbsp;btnLogin_Click(&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;object&lt;/span&gt;&amp;nbsp;sender, EventArgs&amp;nbsp;e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;User&amp;nbsp;_user&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt;&amp;nbsp;User();&lt;br /&gt;&amp;nbsp;&amp;nbsp;DBOperations&amp;nbsp;dbo&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt;&amp;nbsp;DBOperations();&lt;br /&gt;&amp;nbsp;&amp;nbsp;_user&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;dbo.CheckUser(txtUserid.Text);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(_user&amp;nbsp;!&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(_user.Password&amp;nbsp;==&amp;nbsp;txtPassword.Text)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FormsAuthenticationTicket&amp;nbsp;Authticket&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; FormsAuthenticationTicket(1,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;txtUserid.Text,&amp;nbsp;DateTime.Now, DateTime.Now.AddMinutes(30),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;chkRememberMe.Checked,&amp;nbsp;_user.Role, FormsAuthentication.FormsCookiePath);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;hash&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;FormsAuthentication. Encrypt(Authticket);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HttpCookie&amp;nbsp;Authcookie&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt;&amp;nbsp;HttpCookie&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(FormsAuthentication.FormsCookieName, hash);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(Authticket.IsPersistent)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Authcookie.Expires&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; Authticket.Expiration;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Cookies.Add(Authcookie);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;returnUrl&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;Request.QueryString[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"ReturnUrl"&lt;/span&gt;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(returnUrl&amp;nbsp;==&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;returnUrl&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"/"&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Redirect(returnUrl);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;else&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblMessage.Text&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"Password&amp;nbsp;does'nt match."&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;else&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lblMessage.Text&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"User&amp;nbsp;not exists."&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Since the user information is stored as encrypted value in the cookie we need to construct the decrypted version of our credentials for every request and assign it to the Context object. This is done to make the user information available on the pages. The FormsAuthentication module will decrypt the forms authentication ticket in the cookie and make it available through the property HttpContext.Current.User.Identity. A new GenericPrincipal object should be constructed and assigned to the User property of Context object. This has to be done in Application_AuthenticateRequest event in Global.asax file. By default, there will be no Global.asax file added to our solution if you use visual studio 2005 so we need to add it explicitly through "Add new Item."&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 7 - Application Authenticate Event&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;protected&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;void&lt;/span&gt; Application_AuthenticateRequest(Object&amp;nbsp;sender,&amp;nbsp;EventArgs&amp;nbsp;e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(HttpContext.Current.User&amp;nbsp;!&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt; (HttpContext.Current.User.Identity.IsAuthenticated)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(HttpContext.Current.User.Identity&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;is&lt;/span&gt; FormsIdentity)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FormsIdentity&amp;nbsp;id&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; (FormsIdentity)HttpContext.Current.User.Identity;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FormsAuthenticationTicket&amp;nbsp;ticket&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; id.Ticket;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;&amp;nbsp;userInfo&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;ticket.UserData;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;string&lt;/span&gt;[]roles&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;userInfo.Split(',');&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HttpContext.Current.User&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;new&lt;/span&gt; GenericPrincipal(id,&amp;nbsp;roles);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;We need to import System.Security.Principal namespace to the Global.asax file for the above code to work.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 8 - Import Namespace&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;%@&amp;nbsp;Import&amp;nbsp;Namespace="System.Security.Principal" %&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page9" class="pageTitle"&gt;Adding Remember Me Option&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;&amp;nbsp;&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;In the above code the line that creates FormsAuthentication ticket has an argument for specifying cookie as a persistent or non persistent cookie. This attribute is the one that is used for "Remember Me" option in Login pages. Include a Checkbox beneath the password textbox in the login page and assign the &lt;span class="Bold"&gt;Checked&lt;/span&gt; property of the checkbox as the value for the above said argument.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We have completed creating a simple site with role based forms authentication. Now when we run our application, users with admin role can access the resources in admin section publisher section. A user with a publisher role cannot access admin resources while he can access the Publisher section.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;In the next section we will see how to use the LoginView control to show and hide a group of controls on a page.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page10" class="pageTitle"&gt;Using LoginView Control with Roles&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;[ &lt;a href="http://aspalliance.com/1619_Role_Based_Forms_Authentication_in_ASPNET_20.all#top"&gt;Back To Top&lt;/a&gt; ]&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;It can be used to show or hide a group of control or content based on the user login status.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Below is the syntax of using it.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 9 - LoginView Control&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:LoginView&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;ID&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="LoginView1"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;runat&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="server"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;LoggedInTemplate&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;LoggedInTemplate&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;AnonymousTemplate&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;AnonymousTemplate&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:LoginView&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;Things inside &amp;lt;LoggedInTemplate&amp;gt; will be exposed only if the user is already logged in where the things in &amp;lt;AnonymousTemplate&amp;gt; will be visible even if the user is not logged in.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;For example, if we want to display or hide controls based on the user's role then this control is a champion of doing it with very little effort. Consider we have an error page that reports the error to the users. If we want to hide the technical error message to all the users and show the technical error message only for the users with ADMIN role then we can use LoginView control to achieve this requirement.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Refer to the below code for the implementation.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 10 - LoginView Control With Roles&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:LoginView&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;ID&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="loginview"&lt;/span&gt; &lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;runat&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="server"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;RoleGroups&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:RoleGroup&lt;/span&gt;&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;Roles&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;="ADMIN"&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;ContentTemplate&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;b&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;Technical Information:&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;b&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;%=&amp;nbsp;TechnicalErrorMsg&amp;nbsp;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;ContentTemplate&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:RoleGroup&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;RoleGroups&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;asp:LoginView&lt;/span&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The above code will display the technical error messages only to the users with ADMIN Role.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We can also achieve the above with the following code.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 11 - Role Chech In Code&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(User.IsInRole(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"ADMIN"&lt;/span&gt;))&lt;br /&gt;lblMessage.Text&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;TechnicalErrorMsg;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The next sections will describe some of the common problems that we will come across when we use FormsAuthentication and the workarounds to those problems.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page11" class="pageTitle"&gt;Redirecting user to NotAuthorized page&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;When a user who does not belong to admin role is already logged in and has tried accessing the admin section, unfortunately he will be again forwarded to the Login page. Refer to Figure 2.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 2 &amp;ndash; NotAuthorized Problem&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1619/image002.jpg" alt="" width="461" height="153" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;Instead, if a "Not authorized" page is displayed, it will be more appropriate for this scenario.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;We can achieve this by redirecting the user to NotAuthorized page by including the below code in Page_Load event of Login page.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 12 - Not Authorized Page Redirection&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;if&lt;/span&gt;&amp;nbsp;(User.Identity.IsAuthenticated&amp;nbsp;&amp;amp;&amp;amp; Request.QueryString[&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"ReturnUrl"&lt;/span&gt;]&amp;nbsp;!&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;Response.Redirect(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;"NotAuthorized.aspx"&lt;/span&gt;);&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The above code checks whether the user is authenticated and ReturnUrl is not null through which we can confirm that the user is trying to access a resource which he does not have access after authenticating.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a id="#Page12" class="pageTitle"&gt;FormsAuthentication.SignOut() doesnot reflect in LoginStatus and LoginName&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="content" colspan="2"&gt;
&lt;div class="backToTop"&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="KonaBody"&gt;
&lt;p class="MsoNormal"&gt;Suppose, if we have a password reset feature in our ASP.NET site then the user should be forced to logged out once he chooses the new password, and clicked save. He should be asked to login again and verify the new password.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;When a user is already logged in, he can reach the form PasswordReset.aspx and he can choose the new password. When the user types in the new password and clicks save, the user is logged off by calling SignOut() method of FormsAuthentication object. Refer to the code below.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 13 - FormsAuthentication Signout Problem&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;int&lt;/span&gt;&amp;nbsp;res&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; userDAO.ResetPassword(User.Identity.Name,&amp;nbsp;txtOldPassword.Text,&amp;nbsp;&lt;br /&gt;txtConfirmPassword.Text);&lt;br /&gt;lblMessage.Text&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;SUCCESSMSG;&lt;br /&gt;FormsAuthentication.SignOut();&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The actual problem is here. After the password reset is successful the above code will log out the user as planned. But the LoginStatus and LoginName controls on the page will still show the status of the user as logged in as seen in Figure 3.&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Figure 3 &amp;ndash; Signout Problem&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;img src="http://aspalliance.com/ArticleFiles/1619/image003.jpg" alt="" width="497" height="164" /&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;When the form is refreshed or for the subsequent server trip the status of the user that is displayed on the form will be successfully changed to logged out. The cause for this problem is even after the FormsAuthentication.SignOut(); line execution the context information of the current request will still hold the logged in user information. On executing the line Context.User.Identity.Name, the signout code will still give the logged in user information and thus LoginStatus control will not reflect the logout change. From the next request Context.User.Identity.Name will have no value in it which will make the login control to behave correctly.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The work around for the above problem will be making the User attribute of Context object to null.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;The final code is:&lt;/p&gt;
&lt;p class="CodeListingHeading"&gt;Listing 14 - FormsAuthentication Signout Problem Resolution&lt;/p&gt;
&lt;div class="MsoNormal"&gt;
&lt;pre&gt;&lt;span style="color: black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;int&lt;/span&gt;&amp;nbsp;res&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt; userDAO.ResetPassword(User.Identity.Name,&amp;nbsp;txtOldPassword.Text,&amp;nbsp;&lt;br /&gt;txtConfirmPassword.Text);&lt;br /&gt;lblMessage.Text&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;SUCCESSMSG;&lt;br /&gt;FormsAuthentication.SignOut();&lt;br /&gt;Context.User&amp;nbsp;&lt;span style="color: red; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal;"&gt;null&lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p class="MsoNormal"&gt;The other way of solving this problem is by redirecting the user to the login page after changing the password. But you need to have some logic to notify the user that the password is successfully changed.&lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/YQy0OvY-9PY" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/YQy0OvY-9PY/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/Role-Based-Forms-Authentication-in-ASPNET-20.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=d820b114-8596-4ac9-8fea-785beef3c316</guid>
      <pubDate>Sat, 29 Jan 2011 06:11:00 +1400</pubDate>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>Programming Language</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=d820b114-8596-4ac9-8fea-785beef3c316</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=d820b114-8596-4ac9-8fea-785beef3c316</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/Role-Based-Forms-Authentication-in-ASPNET-20.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=d820b114-8596-4ac9-8fea-785beef3c316</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=d820b114-8596-4ac9-8fea-785beef3c316</feedburner:origLink></item>
    <item>
      <title>How to add and remove cookie with JQuery</title>
      <description>&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;// Get the cookie: &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;$.cookie('myCookie'); &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;// Set or update the cookie: &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;$.cookie('myCookie', 'myCookieValue'); &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;// Delete a cookie: &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;$.cookie('sampleCookie', null);&lt;/code&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/vsLtwFkXtcQ" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/vsLtwFkXtcQ/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/How-to-add-and-remove-cookie-with-JQuery.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=ffc6e3c7-655c-4ec4-9874-5c8e042e354d</guid>
      <pubDate>Wed, 05 Jan 2011 20:08:00 +1400</pubDate>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=ffc6e3c7-655c-4ec4-9874-5c8e042e354d</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=ffc6e3c7-655c-4ec4-9874-5c8e042e354d</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/How-to-add-and-remove-cookie-with-JQuery.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=ffc6e3c7-655c-4ec4-9874-5c8e042e354d</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=ffc6e3c7-655c-4ec4-9874-5c8e042e354d</feedburner:origLink></item>
    <item>
      <title>Active Directory - check if a user exists - C#.</title>
      <description>&lt;p&gt;This code snippet, shows how to query active directory and search if a specific username exists.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre class="c-sharp;"&gt;DirectoryEntry directoryEntry = new DirectoryEntry();
directoryEntry.Path = "LDAP://OU=Domain,DC=DomainToSearch,DC=com";
DirectorySearcher directoryEntrySearch = new DirectorySearcher();

directoryEntrySearch.SearchRoot = directoryEntry;
directoryEntrySearch.Filter = "(&amp;amp;(objectClass=user) (cn=" + username + "))";

SearchResultCollection results = directoryEntrySearch.FindAll();

(results.Count &amp;gt; 0) ? Console.WriteLine("Found") : Console.WriteLine("Not Found");&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/r-WEk3mns00" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/r-WEk3mns00/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/Active-Directory-check-if-a-user-exists-C.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=8e8a75e8-f6e1-428a-a6be-83a5c1682259</guid>
      <pubDate>Wed, 05 Jan 2011 20:03:00 +1400</pubDate>
      <category>ASP.NET</category>
      <category>C#</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=8e8a75e8-f6e1-428a-a6be-83a5c1682259</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=8e8a75e8-f6e1-428a-a6be-83a5c1682259</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/Active-Directory-check-if-a-user-exists-C.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=8e8a75e8-f6e1-428a-a6be-83a5c1682259</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=8e8a75e8-f6e1-428a-a6be-83a5c1682259</feedburner:origLink></item>
    <item>
      <title>ASP.NET MVC - writing HTML Helper for creating image link html tag in C#.</title>
      <description>&lt;p&gt;It is very common when you need to use HTML helper in ASP.NET MVC framework to create an image link. &lt;br /&gt; The default set of HTML helpers do not include such HtmlHelper.&lt;br /&gt; This code shows how to write HTML Helper for linking image or just the image tag.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;public static string ImageLink(this HtmlHelper htmlHelper, string imgSrc, string alt, string actionName, string controllerName, object routeValues, object htmlAttributes, object imgHtmlAttributes) {     UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;     string imgtag = htmlHelper.Image(imgSrc, alt, imgHtmlAttributes);     string url = urlHelper.Action(actionName, controllerName, routeValues);      TagBuilder imglink = new TagBuilder("a");     imglink.MergeAttribute("href", url);     imglink.InnerHtml = imgtag;     imglink.MergeAttributes(new RouteValueDictionary(htmlAttributes), true);      return imglink.ToString();  }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and the image tag:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;code class="brush: c-sharp;"&gt;public static string Image(this HtmlHelper htmlHelper, string imgSrc, string alt, object imgHtmlAttributes) {     TagBuilder imgTag = new TagBuilder("img");     imgTag.MergeAttribute("src", imgSrc);     imgTag.MergeAttribute("alt", alt);     imgTag.MergeAttributes(new RouteValueDictionary(imgHtmlAttributes), true);      return imgTag.ToString(); }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/SFJCu0JlSKA" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/SFJCu0JlSKA/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/ASPNET-MVC-writing-HTML-Helper-for-creating-image-link-html-tag-in-C.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=d64a121e-b616-472e-af94-a5c694646722</guid>
      <pubDate>Wed, 05 Jan 2011 20:02:00 +1400</pubDate>
      <category>ASP.NET</category>
      <category>Operating System</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=d64a121e-b616-472e-af94-a5c694646722</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=d64a121e-b616-472e-af94-a5c694646722</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/ASPNET-MVC-writing-HTML-Helper-for-creating-image-link-html-tag-in-C.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=d64a121e-b616-472e-af94-a5c694646722</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=d64a121e-b616-472e-af94-a5c694646722</feedburner:origLink></item>
    <item>
      <title>C# Split String Examples</title>
      <description>&lt;p&gt;You want to split strings on different characters with single  character or string delimiters. For example, split a string that  contains "\r\n" sequences, which are Windows newlines. Through these  examples, we learn ways to use the &lt;strong&gt;Split&lt;/strong&gt; method on the string type in the C# programming language.&lt;/p&gt;
&lt;blockquote&gt;&lt;span style="background: none repeat scroll 0% 0% #ffffe0;"&gt;Use the &lt;strong&gt;Split&lt;/strong&gt; method to separate parts from a string.&lt;/span&gt;&lt;br /&gt;If your input string is A,B,C --&lt;br /&gt;Split on the comma to get an array of:&lt;br /&gt;"A" "B" "C"&lt;/blockquote&gt;
&lt;h2&gt;Using Split&lt;/h2&gt;
&lt;p&gt;To  begin, we look at the basic Split method overload. You already know the  general way to do this, but it is good to see the basic syntax before  we move on. This example splits on a single character.&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Example program for splitting on spaces (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;    static void Main()&lt;br /&gt;    {&lt;br /&gt;        string s = "there is a cat";&lt;br /&gt;        &lt;em&gt;//&lt;br /&gt;        // Split string on spaces.&lt;br /&gt;        // ... This will separate all the words.&lt;br /&gt;        //&lt;/em&gt;&lt;br /&gt;        string[] words = s.&lt;strong style="background: none repeat scroll 0% 0% #e0ffff;"&gt;&lt;span style="text-decoration: underline;"&gt;Split&lt;/span&gt;&lt;/strong&gt;(' ');&lt;br /&gt;        foreach (string word in words)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(word);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Output of the program ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;there&lt;br /&gt;is&lt;br /&gt;a&lt;br /&gt;cat&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Description.&lt;/strong&gt; The input string, which contains four  words, is split on spaces and the foreach loop then displays each word.  The result value from Split is a string[] array.&lt;/p&gt;
&lt;h2&gt;Multiple characters&lt;/h2&gt;
&lt;p&gt;Here  we use either the Regex method or the C# new array syntax. Note that a  new char array is created in the following usages. There is an  overloaded method with that signature if you need StringSplitOptions,  which is used to remove empty strings.&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Program that splits on lines with Regex (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;    static void Main()&lt;br /&gt;    {&lt;br /&gt;        string value = "cat\r\ndog\r\nanimal\r\nperson";&lt;br /&gt;        &lt;em&gt;//&lt;br /&gt;        // Split the string on line breaks.&lt;br /&gt;        // ... The return value from Split is a string[] array.&lt;br /&gt;        //&lt;/em&gt;&lt;br /&gt;        string[] lines = &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Regex.Split&lt;/span&gt;&lt;/strong&gt;(value, "\r\n");&lt;br /&gt;&lt;br /&gt;        foreach (string line in lines)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(line);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Output of the program ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;cat&lt;br /&gt;dog&lt;br /&gt;animal&lt;br /&gt;person&lt;/pre&gt;
&lt;h2&gt;StringSplitOptions&lt;/h2&gt;
&lt;p&gt;While the Regex type methods  can be used to Split strings effectively, the string type Split method  is faster in many cases. The Regex Split method is static; the string  Split method is instance-based. The next example shows how you can  specify an array as the first parameter to string Split.&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Program that splits on multiple characters (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;    static void Main()&lt;br /&gt;    {&lt;br /&gt;        &lt;em&gt;//&lt;br /&gt;        // This string is also separated by Windows line breaks.&lt;br /&gt;        //&lt;/em&gt;&lt;br /&gt;        string value = "shirt\r\ndress\r\npants\r\njacket";&lt;br /&gt;&lt;br /&gt;        &lt;em&gt;//&lt;br /&gt;        // Use a new char[] array of two characters (\r and \n) to break&lt;br /&gt;        // lines from into separate strings. Use "RemoveEmptyEntries"&lt;br /&gt;        // to make sure no empty strings get put in the string[] array.&lt;br /&gt;        //&lt;/em&gt;&lt;br /&gt;        char[] delimiters = new char[] { '\r', '\n' };&lt;br /&gt;        string[] parts = value.&lt;strong style="background: none repeat scroll 0% 0% #e0ffff;"&gt;Split&lt;/strong&gt;(delimiters, StringSplitOptions.RemoveEmptyEntries);&lt;br /&gt;        for (int i = 0; i &amp;lt; parts.Length; i++)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(parts[i]);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;em&gt;//&lt;br /&gt;        // Same as the previous example, but uses a new string of 2 characters.&lt;br /&gt;        //&lt;/em&gt;&lt;br /&gt;        parts = value.&lt;strong style="background: none repeat scroll 0% 0% #e0ffff;"&gt;Split&lt;/strong&gt;(new string[] { "\r\n" }, StringSplitOptions.None);&lt;br /&gt;        for (int i = 0; i &amp;lt; parts.Length; i++)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(parts[i]);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Output of the program ===&lt;/strong&gt;&lt;br /&gt;    &lt;span style="color: blue;"&gt;(Repeated two times)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;shirt&lt;br /&gt;dress&lt;br /&gt;pants&lt;br /&gt;jacket&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overview.&lt;/strong&gt; One useful overload of Split receives  char[] arrays. The string Split method can receive a character array as  the first parameter. Each char in the array designates a new block.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Using string arrays.&lt;/strong&gt; Another overload of Split receives string[] arrays. This means string  array can also be passed to the Split method. The new string[] array is  created inline with the Split call.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Explanation of StringSplitOptions.&lt;/strong&gt; The RemoveEmptyEntries enum is specified. When two delimiters are  adjacent, we end up with an empty result. We can use this as the second  parameter to avoid this. The following screenshot shows the Visual  Studio debugger.&lt;/p&gt;
&lt;p class="l"&gt;&lt;a href="http://dotnetperls.com/stringsplitoptions"&gt;See StringSplitOptions Enumeration.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://dotnetperls.com/EB" alt="Split string debug screenshot" width="537" height="225" /&gt;&lt;/p&gt;
&lt;h2&gt;Separating words&lt;/h2&gt;
&lt;p&gt;Here  we see how you can separate words with Split. Usually, the best way to  separate words is to use a Regex that specifies non-word chars. This  example separates words in a string based on non-word characters. It  eliminates punctuation and whitespace from the return array.&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Program that separates on non-word pattern (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;    static void Main()&lt;br /&gt;    {&lt;br /&gt;        string[] w = SplitWords("That is a cute cat, man");&lt;br /&gt;        foreach (string s in w)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(s);&lt;br /&gt;        }&lt;br /&gt;        Console.ReadLine();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;em&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// Take all the words in the input string and separate them.&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;/em&gt;&lt;br /&gt;    static string[] SplitWords(string s)&lt;br /&gt;    {&lt;br /&gt;        &lt;em&gt;//&lt;br /&gt;        // Split on all non-word characters.&lt;br /&gt;        // ... Returns an array of all the words.&lt;br /&gt;        //&lt;/em&gt;&lt;br /&gt;        return &lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Regex.Split&lt;/span&gt;&lt;/strong&gt;(s, @"\W+");&lt;br /&gt;        &lt;em&gt;// @      special verbatim string syntax&lt;br /&gt;        // \W+    one or more non-word characters together&lt;/em&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Output of the program ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;That&lt;br /&gt;is&lt;br /&gt;a&lt;br /&gt;cute&lt;br /&gt;cat&lt;br /&gt;man&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Word splitting example.&lt;/strong&gt; Here you can separate parts  of your input string based on any character set or range with Regex.  Overall, this provides more power than the string Split methods.&lt;/p&gt;
&lt;p class="l"&gt;&lt;a href="http://dotnetperls.com/regex-split"&gt;See Regex.Split Method Examples.&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Splitting text files&lt;/h2&gt;
&lt;p&gt;Here  you have a text file containing comma-delimited lines of values. This  is called a CSV file, and it is easily dealt with in the C# language. We  use the File.ReadAllLines method here, but you may want StreamReader  instead. This code reads in both of those lines, parses them, and  displays the values of each line after the line number. The final  comment shows how the file was parsed into the strings.&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Contents of input file (TextFile1.txt) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Dog,Cat,Mouse,Fish,Cow,Horse,Hyena&lt;br /&gt;Programmer,Wizard,CEO,Rancher,Clerk,Farmer&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Program that splits lines in file (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;    static void Main()&lt;br /&gt;    {&lt;br /&gt;        int i = 0;&lt;br /&gt;        foreach (string line in File.ReadAllLines("TextFile1.txt"))&lt;br /&gt;        {&lt;br /&gt;            string[] parts = line.&lt;strong style="background: none repeat scroll 0% 0% #e0ffff;"&gt;&lt;span style="text-decoration: underline;"&gt;Split&lt;/span&gt;&lt;/strong&gt;(',');&lt;br /&gt;            foreach (string part in parts)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("{0}:{1}",&lt;br /&gt;                    i,&lt;br /&gt;                    part);&lt;br /&gt;            }&lt;br /&gt;            i++; &lt;em&gt;// For demo only&lt;/em&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Output of the program ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;0:Dog&lt;br /&gt;0:Cat&lt;br /&gt;0:Mouse&lt;br /&gt;0:Fish&lt;br /&gt;0:Cow&lt;br /&gt;0:Horse&lt;br /&gt;0:Hyena&lt;br /&gt;1:Programmer&lt;br /&gt;1:Wizard&lt;br /&gt;1:CEO&lt;br /&gt;1:Rancher&lt;br /&gt;1:Clerk&lt;br /&gt;1:Farmer&lt;/pre&gt;
&lt;h2&gt;Splitting directory paths&lt;/h2&gt;
&lt;p&gt;Here we see how you  can Split the segments in a Windows local directory into separate  strings. Note that directory paths are complex and this may not handle  all cases correctly. It is also platform-specific, and you could use  System.IO.Path. DirectorySeparatorChar for more flexibility.&lt;/p&gt;
&lt;p class="l"&gt;&lt;a href="http://dotnetperls.com/path"&gt;See Path Examples.&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Program that splits Windows directories (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;    static void Main()&lt;br /&gt;    {&lt;br /&gt;        &lt;em&gt;// The directory from Windows&lt;/em&gt;&lt;br /&gt;        const string dir = @"C:\Users\Sam\Documents\Perls\Main";&lt;br /&gt;        &lt;em&gt;// Split on directory separator&lt;/em&gt;&lt;br /&gt;        string[] parts = dir.&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Split&lt;/span&gt;&lt;/strong&gt;('\\');&lt;br /&gt;        foreach (string part in parts)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(part);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Output of the program ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;C:&lt;br /&gt;Users&lt;br /&gt;Sam&lt;br /&gt;Documents&lt;br /&gt;Perls&lt;br /&gt;Main&lt;/pre&gt;
&lt;h2&gt;Internal logic&lt;/h2&gt;
&lt;p&gt;The logic internal to the .NET  framework for Split is implemented in managed code. The methods call  into the overload with three parameters. The parameters are next checked  for validity. Finally, it uses unsafe code to create the separator  list, and then a for loop combined with Substring to return the array.&lt;/p&gt;
&lt;h2&gt;Benchmarks&lt;/h2&gt;
&lt;p&gt;I  tested a long string and a short string, having 40 and 1200 chars.  String splitting speed varies on the type of strings. The length of the  blocks, number of delimiters, and total size of the string factor into  performance. The Regex.Split option generally performed the worst. I  felt that the second or third methods would be the best, after observing  performance problems with regular expressions in other situations.&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Strings used in test (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;em&gt;//&lt;br /&gt;// Build long string.&lt;br /&gt;//&lt;/em&gt;&lt;br /&gt;_test = string.Empty;&lt;br /&gt;for (int i = 0; i &amp;lt; 120; i++)&lt;br /&gt;{&lt;br /&gt;    _test += "01234567\r\n";&lt;br /&gt;}&lt;br /&gt;&lt;em&gt;//&lt;br /&gt;// Build short string.&lt;br /&gt;//&lt;/em&gt;&lt;br /&gt;_test = string.Empty;&lt;br /&gt;for (int i = 0; i &amp;lt; 10; i++)&lt;br /&gt;{&lt;br /&gt;    _test += "ab\r\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Example methods tested (100000 iterations) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;static void Test1()&lt;br /&gt;{&lt;br /&gt;    string[] arr = Regex.Split(_test, "\r\n", RegexOptions.Compiled);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void Test2()&lt;br /&gt;{&lt;br /&gt;    string[] arr = _test.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void Test3()&lt;br /&gt;{&lt;br /&gt;    string[] arr = _test.Split(new string[] { "\r\n" }, StringSplitOptions.None);&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Longer strings: 1200 chars.&lt;/strong&gt; The benchmark for the  methods on the long strings is more even. It may be that for very long  strings, such as entire files, the Regex method is equivalent or even  faster. For short strings, Regex is slowest, but for long strings it is  very fast.&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Benchmark of Split on long strings ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;[1] Regex.Split:    3470 ms&lt;br /&gt;[2] char[] Split:   &lt;span style="background: none repeat scroll 0% 0% #adff2f;"&gt;1255 ms&lt;/span&gt; [fastest]&lt;br /&gt;[3] string[] Split: 1449 ms&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Benchmark of Split on short strings ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;[1] Regex.Split:     434 ms&lt;br /&gt;[2] char[] Split:   &lt;span style="background: none repeat scroll 0% 0% #adff2f;"&gt;  63 ms&lt;/span&gt; [fastest]&lt;br /&gt;[3] string[] Split:   83 ms&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Short strings: 40 chars.&lt;/strong&gt; This  shows the three methods compared to each other on short strings. Method  1 is the Regex method, and it is by far the slowest on the short  strings. This may be because of the compilation time. Smaller is better.  This article was last updated for .NET 3.5 SP1.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Performance recommendation.&lt;/strong&gt; For programs that use shorter strings, the methods that split based on  arrays are faster and simpler, and they will avoid Regex compilation.  For somewhat longer strings or files that contain more lines, Regex is  appropriate. Also, I show some Split improvements that can improve your  program.&lt;/p&gt;
&lt;p class="l"&gt;&lt;a href="http://dotnetperls.com/split-improvement"&gt;See Split String Improvement.&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Escaped characters&lt;/h2&gt;
&lt;p&gt;Here  we note that you can use Replace on your string input to substitute  special characters in for any escaped characters. This can solve lots of  problems on parsing computer-generated code or data.&lt;/p&gt;
&lt;p class="l"&gt;&lt;a href="http://dotnetperls.com/split-escape"&gt;See Split Method and Escape Characters.&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Delimiter arrays&lt;/h2&gt;
&lt;p&gt;In  this section, we focus on how you can specify delimiters to the Split  method in the C# language. My further research into Split and its  performance shows that it is worthwhile to declare your char[] array you  are splitting on as a local instance to reduce memory pressure and  improve runtime performance. There is another example of delimiter array  allocation on this site.&lt;/p&gt;
&lt;p class="l"&gt;&lt;a href="http://dotnetperls.com/split-delimiter"&gt;See Split Delimiter Use.&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Slow version, before (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;//&lt;br /&gt;// Split on multiple characters using new char[] inline.&lt;br /&gt;//&lt;/em&gt;&lt;br /&gt;string t = "string to split, ok";&lt;br /&gt;&lt;br /&gt;for (int i = 0; i &amp;lt; 10000000; i++)&lt;br /&gt;{&lt;br /&gt;    string[] s = t.Split(new char[] { ' ', ',' });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong style="background: none repeat scroll 0% 0% #afeeee; border: 1px solid #dcdcdc;"&gt;=== Fast version, after (C#) ===&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;//&lt;br /&gt;// Split on multiple characters using new char[] already created.&lt;br /&gt;//&lt;/em&gt;&lt;br /&gt;string t = "string to split, ok";&lt;br /&gt;char[] c = new char[]{ ' ', ',' }; &lt;em&gt;// &amp;lt;-- Cache this&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;for (int i = 0; i &amp;lt; 10000000; i++)&lt;br /&gt;{&lt;br /&gt;    string[] s = t.Split(c);&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Interpretation.&lt;/strong&gt; We see that storing the array of  delimiters separately is good. My measurements show the above code is  less than 10% faster when the array is stored outside the loop.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/AGm0IdaQ4f8" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/AGm0IdaQ4f8/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/C-Split-String-Examples.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=29d0a557-27e3-430a-ba96-a6acebd4b895</guid>
      <pubDate>Wed, 22 Dec 2010 05:47:00 +1400</pubDate>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>Programming Language</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=29d0a557-27e3-430a-ba96-a6acebd4b895</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=29d0a557-27e3-430a-ba96-a6acebd4b895</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/C-Split-String-Examples.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=29d0a557-27e3-430a-ba96-a6acebd4b895</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=29d0a557-27e3-430a-ba96-a6acebd4b895</feedburner:origLink></item>
    <item>
      <title>get extension of downloaded file</title>
      <description>&lt;p&gt;
&lt;pre class="brush: c-sharp;"&gt;class Program
{
    static void Main()
    {
        string p = @"C:\Users\Sergio\Documents\Test.txt";

        string e = Path.GetExtension(p);
        if (e == ".txt")
        {
            Console.WriteLine(e);
        }
    }
}&lt;/pre&gt;
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blognhachothue/~4/cYn8P2rHY14" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/blognhachothue/~3/cYn8P2rHY14/post.aspx</link>
      <author>tcdichvunhadat@gmail.com</author>
      <comments>http://blog.nhachothue.net/post/get-extension-of-downloaded-file.aspx#comment</comments>
      <guid isPermaLink="false">http://blog.nhachothue.net/post.aspx?id=c8334aa5-4065-46e6-8e7a-4e8e73db3b86</guid>
      <pubDate>Sun, 05 Dec 2010 21:30:00 +1400</pubDate>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>Programming Language</category>
      <dc:publisher>Admin</dc:publisher>
      <pingback:server>http://blog.nhachothue.net/pingback.axd</pingback:server>
      <pingback:target>http://blog.nhachothue.net/post.aspx?id=c8334aa5-4065-46e6-8e7a-4e8e73db3b86</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://blog.nhachothue.net/trackback.axd?id=c8334aa5-4065-46e6-8e7a-4e8e73db3b86</trackback:ping>
      <wfw:comment>http://blog.nhachothue.net/post/get-extension-of-downloaded-file.aspx#comment</wfw:comment>
      <wfw:commentRss>http://blog.nhachothue.net/syndication.axd?post=c8334aa5-4065-46e6-8e7a-4e8e73db3b86</wfw:commentRss>
    <feedburner:origLink>http://blog.nhachothue.net/post.aspx?id=c8334aa5-4065-46e6-8e7a-4e8e73db3b86</feedburner:origLink></item>
  <media:rating>nonadult</media:rating><media:description type="plain">Tutorials on ASP, ASP.NET and JSP,Search-Engine-Optimization Search</media:description></channel>
</rss>

