<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6011381329995167460</id><updated>2012-01-28T13:01:27.904+05:30</updated><category term='Sql-Server'/><category term='Tips / Tricks'/><title type='text'>Keep it Simple</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>26</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-5417937366571785794</id><published>2009-12-16T20:34:00.033+05:30</published><updated>2009-12-17T09:58:55.582+05:30</updated><title type='text'>Build Secure Web Services With SOAP Headers and Extensions</title><content type='html'>&lt;div align="left"&gt;&lt;span style="font-family:times new roman;"&gt;&lt;span style="font-family:verdana;"&gt;Legions of Web developers have built Web services using the Microsoft .NET Framework and have learned how easy it is to get a basic Web service up and running. Just create an ASMX file, add a class, decorate its methods with the [WebMethod] attribute, and presto! Instant Web service.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;The Framework does the hard part, mapping Web methods to class methods, leaving you to concentrate on the business logic that makes your Web service unique. Building Web services with the .NET Framework is easy—easy, that is, unless the Web services are secure. There is no standard, agreed-upon method for exposing Web services over the Internet in such a way that only authorized users can call them. WS-Security will one day change that, but for now, you're on your own. One Microsoft sample published last year demonstrates how to secure Web services by passing user IDs in method calls. While functional, that approach is less than optimal because it mixes real data with authentication data and, to first order, requires each and every Web method to perform an authorization check before rendering a service. A better solution is one that passes authentication information out-of-band (that is, outside the Web methods' parameter lists) and that "front-ends" each method call with an authentication module that operates independently of the Web methods themselves. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;SOAP headers are the perfect vehicle for passing authentication data out-of-band. SOAP extensions are equally ideal for examining SOAP headers and rejecting calls that lack the required authentication data. Combine the two and you can write secure Web services that cleanly separate business logic from security logic. In this column, I'll present one technique for building secure Web services using SOAP headers and SOAP extensions. Until WS-Security gains the support of the .NET Framework, it's one way to build Web services whose security infrastructure is both centralized and protocol-independent. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;span style="font-family:verdana;"&gt;The Quotes Web Service &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Let's start with the Web service in Figure 1. Called "Quote Service," it publishes a single Web method named GetQuote that takes a stock symbol (for example, "MSFT") as input and returns the current stock price.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure I&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;&lt;span style="font-family:courier new;"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;using System.Web.Services;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;using System.Web.Services.Protocols;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;[WebService (Name="Quote Service", Description="Provides instant stock quotes to registered users")]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;public class QuoteService&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;[WebMethod (Description="Returns the current stock price")]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;public int GetQuote (string symbol)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if (symbol.ToLower () == "msft")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;return 55;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;else if (symbol.ToLower () == "intc")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;return 32;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;throw new SoapException ("Unrecognized symbol", SoapException.ClientFaultCode);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now you can call this web service from your application inorder to test. I guess you know how to test a web service. I did a small test with the Console Application as below. The application should respond by reporting a current stock price of 55.&lt;br /&gt;&lt;br /&gt;Figure II:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;class Client&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;static void Main (string[] args)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;if (args.Length == 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;Console.WriteLine ("Please supply a stock symbol");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;return;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;QuoteService qs = new QuoteService ();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;int price = qs.GetQuote (args[0]);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;Console.WriteLine ("The current price of " + args[0] + " is " + price);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now the &lt;strong&gt;GetQuote &lt;/strong&gt;method is simple enough that anyone can call it. And that's just the problem. Anyone can call it. Assuming you'd want to charge for such a service, you wouldn't want for it to be available to everyone. Rather, you'd want to identify the caller on each call to GetQuote and throw a SOAPException if the caller is not authorized.&lt;br /&gt;&lt;br /&gt;Figure III lists a revised version of Quote Service that uses a custom SOAP header to transmit user names and passwords. A SOAP header is a vehicle for passing additional information in a SOAP message. The general format of a SOAP message is:&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[soap:Envelope xmlns:soap="&lt;a href="http://schemas.xmlsoap.org/soap/envelope/"&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;/a&gt;"] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[soap:Header] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;... &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/soap:Header] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[soap:Body] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;... &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/soap:Body]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/soap:Envelope]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;&lt;span style="color: rgb(0, 0, 0);font-family:verdana;" &gt;SOAP headers are optional. Here's a SOAP message that lacks a header:&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:Trebuchet MS;" &gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:Trebuchet MS;" &gt;[soap:Envelope xmlns:soap="&lt;a href="http://schemas.xmlsoap.org/soap/envelope/"&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;/a&gt;"]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[soap:Body] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[GetQuote xmlns="&lt;a href="http://tempuri.org/"&gt;http://tempuri.org/&lt;/a&gt;"] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[symbol]msft[/symbol] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/GetQuote] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/soap:Body]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;&lt;span style="color: rgb(0, 0, 0);font-family:verdana;" &gt;And here's the same message with a header containing a user name and password:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;&lt;br /&gt;[soap:Envelope xmlns:soap="&lt;a href="http://schemas.xmlsoap.org/soap/envelope/"&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;/a&gt;"] &lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[soap:Header] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[AuthHeader xmlns="&lt;a href="http://tempuri.org/"&gt;http://tempuri.org/&lt;/a&gt;"] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[UserName]techie[/UserName] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[Password]imbest[/Password] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/AuthHeader] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/soap:Header] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[soap:Body] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[GetQuote xmlns="&lt;a href="http://tempuri.org/"&gt;http://tempuri.org/&lt;/a&gt;"] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[symbol]msft[/symbol] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/GetQuote] &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/soap:Body]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);font-family:trebuchet ms;" &gt;[/soap:Envelope]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;"&gt;The .NET Framework lets you define custom SOAP headers by deriving from SoapHeader, which belongs to the &lt;strong&gt;&lt;em&gt;System.Web.Services.Protocols&lt;/em&gt;&lt;/strong&gt; namespace. The following statements in Quotes.asmx define a custom header named &lt;strong&gt;AuthHeader&lt;/strong&gt;:&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;public class AuthHeader : SoapHeader&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;{ &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;public string UserName; &lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;public string Password;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;}&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(153, 0, 0);font-family:Trebuchet MS;" &gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="color: rgb(0, 0, 0);font-family:verdana;" &gt;The statement&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;"&gt;&lt;em&gt;public AuthHeader Credentials;&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;declares an instance of AuthHeader named Credentials in QuoteService, and the statement&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;"&gt;&lt;em&gt;[SoapHeader ("Credentials", Required=true)]&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;makes AuthHeader a required header for calls to GetQuote and transparently maps user names and passwords found in AuthHeaders to the corresponding fields in Credentials.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;Calls lacking AuthHeaders won't even reach GetQuote. Calls that do reach it can be authenticated by reading Credentials' UserName and Password fields. GetQuote checks the user name and password and fails the call if either is invalid:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="color: rgb(51, 0, 153);font-family:courier new;" &gt;if (Credentials.UserName.ToLower () != "techie" &amp;amp;&amp;amp; Credentials.Password.ToLower () != "imbest") &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="color: rgb(51, 0, 153);font-family:courier new;" &gt;throw new SoapException ("Unauthorized", SoapException.ClientFaultCode);&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-family:verdana;"&gt;In the real world, of course, you'd check the caller's credentials against a database rather than hard-code a user name and password. I took the easy way out here to keep the code as simple and understandable as possible.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;"&gt;Figure III&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;%@ WebService Language="C#" Class="QuoteService" %&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:Trebuchet MS;" &gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;%@ WebService Language="C#" Class="QuoteService" %&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web.Services;&lt;br /&gt;using System.Web.Services.Protocols;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;br /&gt;[WebService(Name="Quote Service",Description="Provides instant stock quotes to registered users")]&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;div align="justify"&gt;&lt;br /&gt;public class QuoteService&lt;br /&gt;{&lt;br /&gt;public AuthHeader Credentials;&lt;br /&gt;&lt;br /&gt;[SoapHeader ("Credentials", Required=true)]&lt;br /&gt;[WebMethod (Description="Returns the current stock price")]&lt;br /&gt;public int GetQuote (string symbol)&lt;br /&gt;{&lt;br /&gt;// Fail the call if the caller is not authorized&lt;br /&gt;&lt;div style="text-align: left;"&gt;if (Credentials.UserName.ToLower () != "techie" &amp;amp;&amp;amp; Credentials.Password.ToLower () != "imbest")&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;throw new SoapException ("Unauthorized",SoapException.ClientFaultCode);&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;div align="justify"&gt;&lt;br /&gt;// Process the request&lt;br /&gt;if (symbol.ToLower () == "msft")&lt;br /&gt;return 55;&lt;br /&gt;else if (symbol.ToLower () == "intc")&lt;br /&gt;return 32;&lt;br /&gt;else&lt;br /&gt;&lt;div style="text-align: left;"&gt;throw new SoapException ("Unrecognized symbol",SoapException.ClientFaultCode);&lt;br /&gt;&lt;/div&gt;}&lt;br /&gt;}&lt;/div&gt;&lt;div align="justify"&gt;public class AuthHeader : SoapHeader&lt;br /&gt;{&lt;br /&gt;public string UserName;&lt;br /&gt;public string Password;&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;"&gt;To call this version of Quotes.asmx version of GetQuote, a client must include a SOAP header containing the user name "techie" and the password "imbest" as below.&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="font-family:verdana;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;using System;&lt;br /&gt;class Client&lt;br /&gt;{&lt;br /&gt;static void Main (string[] args)&lt;br /&gt;{&lt;br /&gt;if (args.Length == 0) {&lt;br /&gt;Console.WriteLine ("Please supply a stock symbol");&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;QuoteService qs = new QuoteService ();&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 153);font-family:courier new;" &gt;&lt;div align="justify"&gt;&lt;br /&gt;AuthHeader Credentials = new AuthHeader ();&lt;br /&gt;Credentials.UserName = "techie";&lt;br /&gt;Credentials.Password = "imbest";&lt;br /&gt;qs.AuthHeaderValue = Credentials;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;int price = qs.GetQuote (args[0]);&lt;br /&gt;Console.WriteLine ("The current price of " + args[0] + " is " + price);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;font-family:verdana;" &gt;Voila !! Our web service is secured.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-5417937366571785794?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/5417937366571785794/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=5417937366571785794' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5417937366571785794'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5417937366571785794'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/12/build-secure-web-services-with-soap.html' title='Build Secure Web Services With SOAP Headers and Extensions'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-7586541088371651740</id><published>2009-04-23T11:12:00.034+05:30</published><updated>2009-06-25T16:44:15.020+05:30</updated><title type='text'>Asp.Net 2.0's New SQL Server-Based Cache Invalidation Mechanism</title><content type='html'>&lt;div style="text-align: justify"&gt;With the advent of &lt;span style="font-weight: bold"&gt;SQL Server 2005&lt;/span&gt;, your application can request SQL Server to notify it when critical data in a database has changed. Up to that point, an application can safely continue to retrieve data from the cache. This provides a much more granular level of control and takes any guesswork out of the question of how often the cache should be refreshed. This is possible via a new feature called &lt;span style="font-weight: bold"&gt;Query Notification&lt;/span&gt;, used in conjunction with .NET 2.0.    &lt;br /&gt;    &lt;br /&gt;There are various types of caching available in .Net. Then what's special in Sqlserver query notification. Basically one of the pitfalls with ASP.NET is that it is app domain specific. So if you have a web farm environment, each web server has its own copy of the cache, and this means there is a potential for data being out of sync. &lt;span style="font-weight: bold"&gt;With SQL cache dependency you can cache the data on the web server but have SQL Server notify you when the data changes&lt;/span&gt;.&lt;/div&gt;  &lt;br /&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-weight: bold; color: rgb(255,102,102)"&gt;An overview of Query Notification&lt;/span&gt;&lt;/span&gt;  &lt;br /&gt;  &lt;br /&gt;  &lt;div style="text-align: justify"&gt;A multi-user web application should be able to provide the latest critical data to its users. To be sure of meeting this need, your application may have to retrieve the results from a database every time the user issues the query. However, this unnecessarily increases network round-trips, and is an inefficient use of resources. To reduce the number of round-trips, developers have traditionally relied on caching mechanisms. Once a query is run, the data is subsequently retrieved from the application's local cache. However, the lifetime value of this cache is generally defined so that the application can periodically update the cache with new values from the database, irrespective of whether the data in the back end has changed or not. This is much better, but it is still not precise.   &lt;br /&gt;    &lt;br /&gt;With query notification enabled then when you run a query against the back-end database, you not only retrieve the data into the cache, but also tell SQL Server to register a subscription for notification if the underlying data changes in a way that will affect the result of the query.    &lt;br /&gt;    &lt;br /&gt;When the notification is received, the event handler in your application invalidates the cache and the next time the application runs the query, it will fetch the data from the back-end server.    &lt;br /&gt;    &lt;br /&gt;&lt;span style="font-weight: bold"&gt;All this is done without the need to write any complex application code&lt;/span&gt;.    &lt;br /&gt;&lt;/div&gt;  &lt;br /&gt;  &lt;div style="text-align: justify"&gt;Before you can establish cache dependency with SQL Server 2005, you need to perform the following steps:   &lt;br /&gt;&lt;/div&gt;  &lt;ul&gt;   &lt;li&gt;Configure SQL Server to support SQL Cache invalidation. This is a one-time setup of the tables or databases in the SQL Server database that you want to monitor.&lt;/li&gt;    &lt;li&gt;Add the necessary configuration information to the &lt;span style="font-weight: bold"&gt;web.config&lt;/span&gt; file.&lt;/li&gt; &lt;/ul&gt; &lt;span style="font-size: 130%; color: rgb(255,102,102)"&gt;&lt;span style="font-weight: bold"&gt;Configuration of SQL Server to Support SQL Cache Invalidation&lt;/span&gt;&lt;/span&gt;  &lt;br /&gt;  &lt;br /&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;You can perform the configuration of SQL Server 2000 to support SQL Cache invalidation in two ways:   &lt;br /&gt;&lt;/span&gt;  &lt;ol&gt;   &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;Using the &lt;span style="font-weight: bold"&gt;aspnet_regsql&lt;/span&gt; utilit&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;y&lt;/span&gt;&lt;/li&gt;    &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;Using the &lt;span style="font-weight: bold"&gt;EnableTableForNotifications &lt;/span&gt;method of the &lt;span style="font-weight: bold"&gt;SqlCacheDepen&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;&lt;span style="font-weight: bold"&gt;dencyA&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;&lt;span style="font-weight: bold"&gt;dmin &lt;/span&gt;class&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;div style="text-align: justify"&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;For this article, consider the first method. Basically, the aspnet_regsql utility creates an extra table named &lt;span style="font-weight: bold"&gt;AspNet_SqlCacheTablesForChangeNotification &lt;/span&gt;that is used to keep track of the changes to all the monitored tables in the database. It also cre&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;ates a number of triggers and stored procedures to enable this capability. To run the aspnet_regs&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;ql utility, open up the Visual Studio command prompt and enter the command shown below.&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt; &lt;span style="font-family: verdana,arial,helvetica"&gt;   &lt;br /&gt;Command : &lt;span style="font-weight: bold"&gt;aspnet_regsql -S localhost -U sa -P atanu -d TestDB -ed&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;  &lt;div style="text-align: center"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gOWJOejMX_U/SfAIuigjPZI/AAAAAAAAAKY/4kayM31QrdQ/s1600-h/pic1.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5327767954809634194" style="display: block; margin: 0px auto 10px; width: 398px; cursor: pointer; height: 201px; text-align: center" alt="" src="http://4.bp.blogspot.com/_gOWJOejMX_U/SfAIuigjPZI/AAAAAAAAAKY/4kayM31QrdQ/s400/pic1.JPG" border="0" /&gt;&lt;/a&gt; &lt;span style="font-weight: bold; color: rgb(0,0,153)"&gt;Click the image to enlarge&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt;  &lt;div style="text-align: justify"&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;The command enables the TestDB (My database..you can use your own) database to support SQL cache invalidation:&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt;  &lt;ul&gt;   &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;S—Name of the Server&lt;/span&gt;&lt;/li&gt;    &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;U—User ID to use to connect to the SQL Server&lt;/span&gt;&lt;/li&gt;    &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;P—Password to us&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;e to connect to the SQL Server&lt;/span&gt;&lt;/li&gt;    &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;d—The name of the database&lt;/span&gt;&lt;/li&gt;    &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;ed—Enables the databas&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;e for SQL Server-triggered cache invalidation&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;div style="text-align: justify"&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;Once this is done at the database level, you need to enable cache invalidation at the individual table level.&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt; &lt;span style="font-family: verdana,arial,helvetica"&gt;   &lt;br /&gt;Command :&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;&lt;span style="font-weight: bold"&gt;aspnet_regsq&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;&lt;span style="font-weight: bold"&gt;l -S localhost -U sa -P atanu -t Products -d TestDB -et     &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;  &lt;div style="text-align: center"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gOWJOejMX_U/SfAKwi79EII/AAAAAAAAAKg/E5vxTA8APZ8/s1600-h/pic1.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5327770188307566722" style="display: block; margin: 0px auto 10px; width: 400px; cursor: pointer; height: 202px; text-align: center" alt="" src="http://2.bp.blogspot.com/_gOWJOejMX_U/SfAKwi79EII/AAAAAAAAAKg/E5vxTA8APZ8/s400/pic1.JPG" border="0" /&gt;&lt;/a&gt;&lt;span style="font-weight: bold; color: rgb(0,0,153)"&gt; Click the image to enlarge&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt; &lt;span style="font-family: verdana,arial,helvetica"&gt;In the above command:&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;   &lt;br /&gt;&lt;/span&gt;  &lt;ul&gt;   &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;t—Specifies the name of the table&lt;/span&gt;&lt;/li&gt;    &lt;li&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;et—Enables the table&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt; for SQL Server-triggered cache invalidation&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;div style="text-align: justify"&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;The preceding screenshot shows how to enable SQL cache invalidation for the Products table in the TestDB database. Once you configure the Products table to send notifications, any time data in the table changes, it notifies ASP.NET to invalidate the corresponding item in the cache.&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt; &lt;span style="font-family: verdana,arial,helvetica"&gt;   &lt;br /&gt;&lt;span style="font-size: 130%; color: rgb(255,102,102)"&gt;&lt;span style="font-weight: bold"&gt;Web Configuration Settings for SQL Cache Invalidation&lt;/span&gt;&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;  &lt;div style="text-align: justify"&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;The next step, before you can &lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;use SQL cache invalidation in your ASP.NET application, is to update the Web configuration file. You need to instruct the ASP.NET framework to poll the databases that you have enabled for SQL cache invalidation. The following Web configuration file contains the necessary configuration information to poll the &lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;TestDB &lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;database at periodic intervals:&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt; &lt;connectionstrings&gt;&lt;add connectionstring="server=Personal;database=TestDB;UID=sa;PWD=atanu" name="TestDbConnection"&gt;&lt;/add&gt;&lt;system.web&gt;&lt;caching&gt;  &lt;br /&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;  &lt;div style="text-align: center"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gOWJOejMX_U/SfANxqjdEmI/AAAAAAAAAKo/tO1gS4i27vI/s1600-h/pic1.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5327773506067042914" style="display: block; margin: 0px auto 10px; width: 577px; cursor: pointer; height: 138px; text-align: center" alt="" src="http://2.bp.blogspot.com/_gOWJOejMX_U/SfANxqjdEmI/AAAAAAAAAKo/tO1gS4i27vI/s400/pic1.JPG" border="0" /&gt;&lt;/a&gt;&lt;span style="font-weight: bold; color: rgb(0,0,153)"&gt;Click the image to enlarge&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt;  &lt;br /&gt;  &lt;div style="text-align: justify"&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;The preceding Web configuration file contains two sections, [&lt;span style="font-weight: bold"&gt;connectionStrings&lt;/span&gt;] and [&lt;span style="font-weight: bold"&gt;caching&lt;/span&gt;]. The &lt;span style="font-weight: bold; color: rgb(255,0,0)"&gt;connectionStrings &lt;/span&gt;section creates a database connection string to the TestDB database named &amp;quot;&lt;span style="font-weight: bold"&gt;TestDbConnection&lt;/span&gt;&amp;quot;. The caching section configures the SQL cache invalidation polling. Within the databases subsection, you list one or more databases that you want to poll for changes. The add section inside the databases section indicates that the database represented by &amp;quot;TestDB&amp;quot; is polled once a minute (every 60,000 milliseconds). You can specify different polling intervals for different databases. Remember, the server must do a little bit of work every time the database is polled for changes. If you don't expect the data in the database to change very often, you should increase the polling interval.&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt; &lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;  &lt;br /&gt;&lt;databases&gt;&lt;span style="font-size: 130%; color: rgb(255,102,102)"&gt;&lt;span style="font-weight: bold"&gt;Enabling query notification in ASP.NET using SQLCacheDependency&lt;/span&gt;&lt;/span&gt;  &lt;br /&gt;  &lt;br /&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;  &lt;div style="text-align: justify"&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;Now that you have performed the required configurations, you are ready to take advantage of the SQL cache invalidation feature in your ASP.NET Web page. Add a new Web form named Default.aspx to your Web site. The following is the code for the &lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;Default&lt;/span&gt;&lt;span style="font-family: verdana,arial,helvetica"&gt;.aspx where we are going to bind a Grid with the data of the &lt;span style="font-weight: bold"&gt;Products &lt;/span&gt;table.&lt;/span&gt;    &lt;br /&gt;&lt;/div&gt;  &lt;br /&gt;&lt;span style="font-size: 130%; color: rgb(51,102,255); font-family: courier new"&gt;using &lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;System.Data.SqlClient;&lt;/span&gt;&lt;span style="font-size: 130%"&gt;   &lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; color: rgb(51,102,255); font-family: courier new"&gt;using &lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;System.Web.Caching;&lt;/span&gt;  &lt;br /&gt;  &lt;br /&gt;&lt;span style="font-size: 130%; color: rgb(51,51,255); font-family: courier new"&gt;protected void&lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt; Page_Load(&lt;/span&gt;&lt;span style="font-size: 130%; color: rgb(51,102,255); font-family: courier new"&gt;object &lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;sender, &lt;/span&gt;&lt;span style="font-size: 130%; color: rgb(51,153,153); font-family: courier new"&gt;EventArgs &lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;e)&lt;/span&gt;&lt;span style="font-size: 130%"&gt;   &lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;{ &lt;/span&gt;&lt;span style="font-size: 130%"&gt;   &lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;GridView1.DataSource = bindCachedData();&lt;/span&gt;&lt;span style="font-size: 130%"&gt;   &lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;GridView1.DataBind();&lt;/span&gt;&lt;span style="font-size: 130%"&gt;   &lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 130%; font-family: courier new"&gt;}&lt;/span&gt;  &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;  &lt;br /&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,102,255)"&gt;private &lt;/span&gt;&lt;span style="color: rgb(51,153,153)"&gt;DataSet &lt;/span&gt;bindCachedData()&lt;/span&gt;    &lt;br /&gt;&lt;span style="font-family: courier new"&gt;{&lt;/span&gt;    &lt;br /&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;  &lt;div style="text-align: left"&gt;   &lt;div style="text-align: left"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,102,255)"&gt;&lt;/span&gt;&lt;span style="color: rgb(51,153,153)"&gt;DataSet &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;dsProducts;&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;dsProducts = (&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,102,255)"&gt;&lt;/span&gt;&lt;span style="color: rgb(51,153,153)"&gt;DataSet&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;)Cache.Get(&amp;quot;Products&amp;quot;);&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;if (dsProducts == null)&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,153,153)"&gt;SqlConnection &lt;/span&gt;sqlcon = new &lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,153,153)"&gt;SqlConnection&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;(&lt;span style="color: rgb(51,153,153)"&gt;ConfigurationManager&lt;/span&gt;.ConnectionStrings[&amp;quot;&lt;span style="color: rgb(153,51,0)"&gt;TestDbConnection&lt;/span&gt;&amp;quot;]          &lt;br /&gt;.ConnectionString);&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,153,153)"&gt;SqlDataAdapter &lt;/span&gt;adapter = new &lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,153,153)"&gt;SqlDataAdapter&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;(&amp;quot;&lt;span style="color: rgb(153,51,0)"&gt;Select * from Products&lt;/span&gt;&amp;quot;, sqlcon);&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;dsProducts = new &lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,102,255)"&gt;&lt;/span&gt;&lt;span style="color: rgb(51,153,153)"&gt;DataSet&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;adapter.Fill(dsProducts);&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,153,153)"&gt;SqlCacheDependency &lt;/span&gt;dependency = new &lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;&lt;span style="color: rgb(51,153,153)"&gt;SqlCacheDependency&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;(&amp;quot;&lt;span style="color: rgb(153,51,0)"&gt;TestDbConnection&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: rgb(153,51,0)"&gt;Products&lt;/span&gt;&amp;quot;);&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;Cache.Insert(&amp;quot;&lt;span style="color: rgb(153,51,0)"&gt;Products&lt;/span&gt;&amp;quot;, dsProducts, dependency); &lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;return dsProducts;&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;span style="font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;databases&gt;&lt;add name="TestDbConnection" polltime="60000" connectionstringname="TestDbConnection"&gt;&lt;/add&gt;&lt;/databases&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;      &lt;br /&gt;      &lt;div style="text-align: justify"&gt;&lt;span class="clsBlurb"&gt;&lt;span class="clsBlurb"&gt;In the above code, you start by creating an instance of the &lt;span style="font-weight: bold"&gt;SqlConnection &lt;/span&gt;object passing in the connection string that is retrieved from the web.config file. Then you create an instance of the &lt;span style="font-weight: bold"&gt;SqlDataAdapter &lt;/span&gt;object and pass in the SQL statement to be executed and the previously created SqlConnection object as its arguments. Then you execute the SQL query using the &lt;span style="font-weight: bold"&gt;Fill&lt;/span&gt; method of the SqlDataAdapter object. After that you create an instance of the &lt;span style="font-weight: bold"&gt;SqlCacheDependency &lt;/span&gt;object and supply the database name (that corresponds to the database name specified in the web.config file) and the table name as its arguments. Then you insert the categories dataset to the cache using the &lt;span style="font-weight: bold"&gt;Insert &lt;/span&gt;method of the &lt;span style="font-weight: bold"&gt;Cache &lt;/span&gt;object. At the time of inserting, you should also specify the SqlCacheDependency object so that the dataset can be invalidated when the data in the &lt;span style="font-weight: bold"&gt;Product &lt;/span&gt;table changes. Finally, you bind the dataset to the GridView control.&lt;/span&gt;&lt;/span&gt;        &lt;br /&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;sqlcachedependency polltime="60000" enabled="true"&gt;&lt;/sqlcachedependency&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;/div&gt;   &lt;/div&gt; &lt;/div&gt;  &lt;div style="text-align: justify"&gt;   &lt;div style="text-align: justify"&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;The first time this application loads, there will be nothing in the application cache and &lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;span style="font-weight: bold; font-size: 130%"&gt;&lt;span style="font-family: courier new"&gt;dsProducts&lt;/span&gt;&lt;/span&gt;&lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;span style="font-weight: bold"&gt; &lt;/span&gt;will be null. As a result, the query will be called. When this happens, the function will register a notification subscription with SQL Server. It will also load up the cache with the output of our query. When the user runs this query again the data will be retrieved from the cache. You can confirm this by running the app in&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt; &lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;debug mode.&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;      &lt;br /&gt;&lt;/div&gt;    &lt;div style="text-align: justify"&gt;&lt;span class="clsBlurb"&gt;&lt;span class="clsBlurb"&gt;To test if the SQL Server based cache invalidation mechanism works, modify the data in the Products table and then if you navigate to the page using the browser, you will get the changed data as retrieved from the database. &lt;/span&gt;&lt;/span&gt;      &lt;br /&gt;&lt;/div&gt; &lt;connectionstrings&gt;&lt;system.web&gt;&lt;caching&gt;&lt;/caching&gt;&lt;/system.web&gt;&lt;/connectionstrings&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-7586541088371651740?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/7586541088371651740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=7586541088371651740' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/7586541088371651740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/7586541088371651740'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/04/aspnet-20s-new-sql-server-based-cache.html' title='Asp.Net 2.0&amp;#39;s New SQL Server-Based Cache Invalidation Mechanism'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_gOWJOejMX_U/SfAIuigjPZI/AAAAAAAAAKY/4kayM31QrdQ/s72-c/pic1.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-8318906442467518558</id><published>2009-04-19T11:01:00.015+05:30</published><updated>2010-03-02T18:45:05.835+05:30</updated><title type='text'>Garbage Collection in .NET - How it really works</title><content type='html'>&lt;span style="font-weight: bold; color: rgb(204, 0, 0);font-size:100%;" &gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Garbage &lt;/span&gt;collection is a process of releasing the memory used by the objects,  which are no longer referenced. This is done in  different ways and different  manners in various platforms and languages. We will see how garbage collection  is being done in .NET.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 102, 102); font-weight: bold;font-size:130%;" &gt;Garbage Collection bas&lt;/span&gt;&lt;span style="color: rgb(255, 102, 102); font-weight: bold;font-size:130%;" &gt;is&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Almost every program uses resources such as  database connection, file system objects etc. In order to make use of these  things some resources should be available to us. &lt;/li&gt;&lt;li&gt;First we allocate a block of memory in the  managed memory by using the new keyword. &lt;/li&gt;&lt;li&gt;Use the constructor of the class to set the  initial state of the object.&lt;/li&gt;&lt;li&gt;Use the resources by accessing the type's members&lt;/li&gt;&lt;li&gt;At last &lt;span style="font-weight: bold;"&gt;CLEAR  THE MEMORY&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;But how many times have programmers forgotten to  release the memory. Or how many times the programmers try to access the memory  which was cleaned.&lt;br /&gt;&lt;br /&gt;These two are the serious bugs, which will lead us to memory leak and commonly  occurring. In order to overcome these things the concept of automatic memory  management has come. Automatic memory management or Automatic garbage collection  is a process by which the system will automatically take care of the memory used  by unwanted objects (we call them as garbage) to be released. Hurrah... Thanks  to Microsoft's Automatic Garbage collection mechanism.&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Automatic Garbage Collection in  .NET&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When Microsoft planned to go for a new generation platform called .NET with  the new generation language called C#, their first intention is to make a  language which is developer friendly to learn and use it with having rich set of  APIs to support end users as well. So they put a great thought in Garbage  Collection and come out with this model of automatic garbage collection in  .NET.&lt;br /&gt;&lt;br /&gt;They implemented garbage collector as a separate thread. This thread will be  running always at the back end. Some of us may think, running a separate thread  will make extra overhead. Yes. It is right. That is why the garbage collector  thread is given the lowest priority. But when system finds there is no space in  the managed heap (managed heap is nothing but a bunch of memory allocated for  the program at run time), then garbage collector thread will be given &lt;span style="font-weight: bold;"&gt;REALTIME&lt;/span&gt;  priority (REALTIME priority is the highest priority in Windows) and collect all  the un wanted objects.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);font-size:130%;" &gt;How does Garbage collector locate garbage&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When an program is loaded in the memory there will be a bunch of memory  allocated for that particular program alone and loaded with the memory. This  bunch of memory is called Managed Heap in .NET world. This amount of memory  will only be used when an object is to be loaded in to the memory for that  particular program.&lt;br /&gt;&lt;br /&gt;This memory is separated in to three parts :&lt;ul&gt;&lt;li&gt;Generation Zero&lt;/li&gt;&lt;li&gt;Generation One&lt;/li&gt;&lt;li&gt;Generation Two&lt;/li&gt;&lt;/ul&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_gOWJOejMX_U/Seq7B19LzDI/AAAAAAAAAJw/fw_abNAutTg/s1600-h/Pic1.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 59px;" src="http://3.bp.blogspot.com/_gOWJOejMX_U/Seq7B19LzDI/AAAAAAAAAJw/fw_abNAutTg/s320/Pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5326275149657001010" border="0" /&gt;&lt;/a&gt;Ideally Generation zero will be in smaller size, Generation one will be in  medium size and Generation two will be larger.&lt;br /&gt;&lt;br /&gt;When we try to create an object by using NEW keyword the system will,&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Calculate the number of bytes required for  the object or type to be loaded in to the managed heap.&lt;/li&gt;&lt;li&gt;The CLR then checks that the bytes required  to allocate the object are available in the reserved region (committing storage  if necessary). IF the object fits, it is allocated at the address pointed to by &lt;span style="font-weight: bold;"&gt;  &lt;/span&gt;&lt;code style="font-weight: bold;"&gt;NextObjPtr&lt;/code&gt;.&lt;/li&gt;&lt;li&gt;These processes will happen at the  &lt;span style="font-weight: bold;"&gt;Generation zero level&lt;/span&gt;.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gOWJOejMX_U/Seq8PUwUkhI/AAAAAAAAAJ4/fdJtP8TTEdU/s1600-h/Pic1.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 55px;" src="http://2.bp.blogspot.com/_gOWJOejMX_U/Seq8PUwUkhI/AAAAAAAAAJ4/fdJtP8TTEdU/s320/Pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5326276480774476306" border="0" /&gt;&lt;/a&gt;When Generation Zero is full and it does not have enough space to occupy  other objects but still the program wants to allocate some more memory for some  other objects, then the garbage collector will be given the &lt;span style="font-weight: bold;"&gt;REALTIME &lt;/span&gt;priority  and will come in to picture.&lt;br /&gt;&lt;br /&gt;Now the garbage collector will come and check all the objects in the Generation  Zero level.              If an object's scope and lifetime goes off then the system will automatically  mark it for garbage collection.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;Note:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here in the process the object is just marked and not collected. Garbage  collector will only collect the object and free the  memory.&lt;br /&gt;&lt;br /&gt;Garbage collector will come and start examining all the objects in the level  Generation Zero right from the beginning. If it finds any object marked for  garbage collection, it will simply remove those objects from the  memory.&lt;br /&gt;&lt;br /&gt;Here comes the important part. Now let us refer the figure below.  There are three objects in the managed heap. If A and C are not marked but B has  lost it scope and lifetime. So B should be marked for garbage collection. So  object B will be collected and the managed heap will look like this.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gOWJOejMX_U/Seq9ZSA8WXI/AAAAAAAAAKA/VgYOTil45fU/s1600-h/Pic1.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 50px;" src="http://2.bp.blogspot.com/_gOWJOejMX_U/Seq9ZSA8WXI/AAAAAAAAAKA/VgYOTil45fU/s320/Pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5326277751349205362" border="0" /&gt;&lt;/a&gt;But do remember that the system will come and  allocate the new objects only at the last. It does not see in between. So it is  the job of garbage collector to compact the memory structure after collecting  the objects. It does that also. So the memory would be looking like as shown  below now.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gOWJOejMX_U/Seq94JWP5bI/AAAAAAAAAKI/ObR_N-gjrVQ/s1600-h/Pic1.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 57px;" src="http://4.bp.blogspot.com/_gOWJOejMX_U/Seq94JWP5bI/AAAAAAAAAKI/ObR_N-gjrVQ/s320/Pic1.JPG" alt="" id="BLOGGER_PHOTO_ID_5326278281598592434" border="0" /&gt;&lt;/a&gt;But garbage collector does not come to end after  doing this. It will look which are all the objects survive after the sweep  (collection). Those objects will be moved to &lt;span style="font-weight: bold;"&gt;Generation One&lt;/span&gt; and now the  Generation Zero is empty for filling new objects.&lt;br /&gt;&lt;br /&gt;If Generation One does not have space for objects  from Generation Zero, then the process happened in Generation Zero will happen  in Generation one as well. This is the same case with &lt;span style="font-weight: bold;"&gt;Generation Two&lt;/span&gt;  also.&lt;br /&gt;&lt;br /&gt;You may have a doubt, all the generations are  filled with the referred objects and still system or our program wants to  allocate some objects, then what will happen? If so, then the  &lt;code style="font-family: georgia; color: rgb(204, 0, 0); font-weight: bold;"&gt;MemoryOutofRangeException&lt;/code&gt;&lt;span style="color: rgb(204, 0, 0); font-weight: bold;font-family:georgia;" &gt; &lt;/span&gt;will be thrown.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 102);font-size:130%;" &gt;Dispose&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Instead of declaring a Finalizer, exposing a Dispose method is considered as good.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:100%;color:DarkBlue;" id="ctl00_ContentPlaceHolder1_lblDescription"  &gt;&lt;pre&gt;public void Dispose()&lt;br /&gt;{&lt;br /&gt;// all clean up source code here..&lt;br /&gt;GC.SuppressFinalize(this);&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;If we clean up a object, using Dispose or Close method, we should indicate to the runtime that the object is no longer needed finalization, by calling &lt;span style="font-weight: bold;"&gt;GC.SuppressFinalize()&lt;/span&gt; as shown above.&lt;br /&gt;&lt;br /&gt;If we are creating and using objects that have &lt;span style="font-weight: bold;"&gt;Dispose &lt;/span&gt;or &lt;span style="font-weight: bold;"&gt;Close &lt;/span&gt;methods, we should call these methods when we’ve finished using these objects. It is advisable to place these calls in a finally clause, which guarantees that the objects are properly handled even if an exception is thrown.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-8318906442467518558?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/8318906442467518558/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=8318906442467518558' title='42 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8318906442467518558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8318906442467518558'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/04/garbage-collection-in-net.html' title='Garbage Collection in .NET - How it really works'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_gOWJOejMX_U/Seq7B19LzDI/AAAAAAAAAJw/fw_abNAutTg/s72-c/Pic1.JPG' height='72' width='72'/><thr:total>42</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-3614587495519280863</id><published>2009-04-15T19:55:00.007+05:30</published><updated>2009-04-15T20:18:14.985+05:30</updated><title type='text'>Exploring the Factory Design Pattern</title><content type='html'>Software changes. This is a rather obvious statement, but it is a fact that must be ever present in the minds of developers and architects. Although we tend to think of software development as chiefly an engineering exercise, the analogy breaks down very quickly. When was the last time someone asked the designers of the Empire State building to add ten new floors at the bottom, put a pool on the top, and have all of this done before Monday morning?&lt;br /&gt;&lt;br /&gt;This is a daunting challenge. We must design systems that are capable of changing at a moment's notice. Be it requirements, technology, or personnel, there will be change and we must be prepared. If we forget this, we do so at our own peril.&lt;br /&gt;&lt;br /&gt;Although this can be a frightening proposition, there are a great many tools at our disposal to ensure that systems are designed to change rapidly while reducing the negative impact these alterations can bring. One such tool is design patterns. Design patterns represent a wealth of collective knowledge and experience. The proper use of these patterns will help to ensure that systems are malleable, enabling rapid change.&lt;br /&gt;&lt;br /&gt;Over the course of this article, I will try examine in short one of the most commonly used patterns, the &lt;strong&gt;Factory&lt;/strong&gt; pattern.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);font-size:130%;" &gt;Factory Pattern&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;An important facet of system design is the manner in which objects are created. Although far more time is often spent considering the object model and instance interaction, if this simple design aspect is ignored it will adversely impact the entire system. Thus, it is not only important what an object does or what it models, but also in what manner it was created.&lt;br /&gt;&lt;br /&gt;Since most object-oriented languages and runtimes provide object instantiation (e.g. new, newobj, etc.) and initialization (e.g. constructors) mechanisms, there may be a tendency to simply use these facilities directly without forethought to future consequences. The overuse of this functionality often introduces a great deal of the inflexibility in the system, as the direct use of a language/run-time object instantiation function creates an explicit association between the creator and created classes. While associations are a necessary type of relationship in an object-oriented system, the coupling introduced between classes is extremely difficult to overcome should requirements change (as they always do).&lt;br /&gt;&lt;br /&gt;One of the most widely used creational patterns is the &lt;strong&gt;Factory&lt;/strong&gt;. This pattern is aptly named, as it calls for the use of a specialized object solely to create other objects, much like a real-world factory. In the following sections, we will examine the basic knowledge of this pattern which will help you to adopt this design pattern quickly.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Logical Model&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As with other design patterns, there are countless variations of the Factory pattern, although most variants typically used the same set of primary actors, a &lt;strong&gt;client&lt;/strong&gt;, a &lt;strong&gt;factory&lt;/strong&gt;, and a &lt;strong&gt;product&lt;/strong&gt;. The client is an object that requires an instance of another object (the product) for some purpose. Rather than creating the product instance directly, the client delegates this responsibility to the factory. Once invoked, the factory creates a new instance of the product, passing it back to the client. Put simply, the client uses the factory to create an instance of the product. &lt;strong&gt;Below figure &lt;/strong&gt;shows this logical relationship between these elements of the pattern.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gOWJOejMX_U/SeXxNLjS8GI/AAAAAAAAAJY/6GKcQHUqKZU/s1600-h/aaa.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 54px;" src="http://2.bp.blogspot.com/_gOWJOejMX_U/SeXxNLjS8GI/AAAAAAAAAJY/6GKcQHUqKZU/s400/aaa.gif" alt="" id="BLOGGER_PHOTO_ID_5324927343176904802" border="0" /&gt;&lt;/a&gt;The factory completely abstracts the creation and initialization of the product from the client. This indirection enables the client to focus on its discrete role in the application without concerning itself with the details of how the product is created. Thus, as the product implementation changes over time, the client remains unchanged.&lt;br /&gt;&lt;br /&gt;While this indirection is a tangible benefit, the most important aspect of this pattern is the fact that the client is abstracted from both the type of product and the type of factory used to create the product. Presuming that the product interface is invariant, this enables the factory to create any product type it deems appropriate. Furthermore, presuming that the factory interface is invariant, the entire factory along with the associated products it creates can be replaced in a wholesale fashion. Both of these radical modifications can occur without any changes to the client.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Consider an application that models the assembly of a variety of personal computers. The application contains a &lt;strong&gt;ComputerAssembler&lt;/strong&gt; class that is responsible for the assembly of the computer, a &lt;strong&gt;Computer&lt;/strong&gt; class that models the computer being built, and a &lt;strong&gt;ComputerFactory &lt;/strong&gt;class that creates instances of the &lt;strong&gt;Computer&lt;/strong&gt; class. In using the Factory pattern, the &lt;strong&gt;ComputerAssembler&lt;/strong&gt; class delegates responsibility for creation of &lt;strong&gt;Computer&lt;/strong&gt; instances to the &lt;strong&gt;ComputerFactory&lt;/strong&gt;. This ensures that if the instantiation and/or initialization process changes (e.g. new constructor, use of an activator, custom pooling, etc.), the &lt;strong&gt;ComputerAssembler&lt;/strong&gt; does not need to change at all. This is the benefit of abstracting the creation of an object from its use. &lt;/p&gt;  &lt;p&gt;In addition, suppose that the business requirements changed and a new type of computer needs to be assembled. Rather than modifying the &lt;strong&gt;ComputerAssembler&lt;/strong&gt; class directly, the &lt;strong&gt;ComputerFactory &lt;/strong&gt;class can be modified to create instances of a new computer class (assuming that this new class has the same interface as &lt;strong&gt;Computer&lt;/strong&gt;). Furthermore, it is also possible to address this requirement by creating a new factory class (that has the same interface as &lt;strong&gt;ComputerFactory&lt;/strong&gt;) that creates instances of the new computer class (again, with the same interface as &lt;strong&gt;Computer&lt;/strong&gt;). As before, nothing in the &lt;strong&gt;ComputerAssembler&lt;/strong&gt; class needs to change, all the logic just continues to work as it had previously.This is the benefit of abstracting the types of the product and factory into invariant interfaces.&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(204, 0, 0);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;As I conclude this examination of the of the &lt;span style="font-weight: bold;"&gt;Factory &lt;/span&gt;pattern, it should be apparent that this pattern offers considerable benefits. From the abstraction of instance creation to the use of immutable product and factory interfaces, this pattern provides a clear mechanism to design flexible system that are highly adaptable. The inclusion of this pattern in the .NET Framework is a clear testament to it usefulness. Regardless of the nature of your application, this pattern can help it weather the winds of change.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-3614587495519280863?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/3614587495519280863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=3614587495519280863' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/3614587495519280863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/3614587495519280863'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/04/exploring-factory-design-pattern.html' title='Exploring the Factory Design Pattern'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_gOWJOejMX_U/SeXxNLjS8GI/AAAAAAAAAJY/6GKcQHUqKZU/s72-c/aaa.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-7636848010766647867</id><published>2009-04-02T11:30:00.007+05:30</published><updated>2009-04-02T11:55:39.309+05:30</updated><title type='text'>Native XML Web Services in SQL Server 2005 - Creating HTTP Endpoints</title><content type='html'>&lt;div&gt;With SQL Server 2005 developers will be able to develop Web services in the database tier, making SQL Server a hypertext transfer protocol (HTTP) listener and providing a new type of data access capability for Web services-centric applications.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Native XML Web Services in SQL Server 2005&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To begin, you need to be running Windows 2003 or Windows XP SP2 to use this feature and you don't need IIS. In fact, if you are running IIS, it may cause a problem if both SQL Server 2005 and IIS are both listening to port 80 when you try to create your HTTP Endpoint.  For this tutorial, I would just stop IIS if you have it running. If you don't want to do that, you will need to change the default port that either IIS or SQL Server 2005 is using to listen to HTTP Requests. The default is 80, and one of them will need to be changed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Expose Stored Procedure as XML Web Service&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;My goal is pretty simple. I want to expose a stored procedure, called &lt;span style="font-weight: bold;"&gt;GetContacts&lt;/span&gt;, in my &lt;span style="font-weight: bold;"&gt;AdventureWorks &lt;/span&gt;Database as an XML Web Service. As luck would have it, this is an extremely easy thing to do in SQL Server 2005 without requiring IIS.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gOWJOejMX_U/SdRWCP39D9I/AAAAAAAAAJA/Lx2hVaYQCsE/s1600-h/adventureworksstoredprocedure.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 230px;" src="http://4.bp.blogspot.com/_gOWJOejMX_U/SdRWCP39D9I/AAAAAAAAAJA/Lx2hVaYQCsE/s400/adventureworksstoredprocedure.jpg" alt="" id="BLOGGER_PHOTO_ID_5319971656452345810" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;CREATE PROCEDURE [dbo].[GetContacts&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;    SET NOCOUNT ON;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;    SELECT TOP 20 [FirstName],[LastName] FROM&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;       [Person].[Contact] ORDER BY [LastName];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;END&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Create HTTP Endpoint&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Fire up &lt;span style="font-weight: bold;"&gt;SQL Server Management Studio&lt;/span&gt;, choose the &lt;span style="font-weight: bold;"&gt;AdventureWorks &lt;/span&gt;Database, and open a New Query Window.  Create an &lt;span style="font-weight: bold;"&gt;HTTP&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; En&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;dpoint&lt;/span&gt; with the following statement:&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;CREATE ENDPOINT AW_Contacts&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;    STATE = Started&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;AS HTTP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;    (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        PATH = '/Contacts',&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        AUTHENTICATION = (INTEGRATED),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        PORTS = (CLEAR),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        SITE = '*'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;    )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;FOR SOAP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;    (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        WEBMETHOD 'GetContacts'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;            (NAME = 'AdventureWorks.dbo.GetContacts'),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        WSDL = DEFAULT,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        DATABASE = 'AdventureWorks',&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;        NAMESPACE = DEFAULT&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;    )&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;If you get an error executing this query that mentions another service using the port, make sure you turn off IIS.&lt;br /&gt;&lt;br /&gt;A &lt;span style="font-weight: bold;"&gt;Path &lt;/span&gt;= '/Contacts', &lt;span style="font-weight: bold;"&gt;Site &lt;/span&gt;= '*', and &lt;span style="font-weight: bold;"&gt;Ports &lt;/span&gt;= (CLEAR) means that your URL will be to the default host, &lt;span style="font-weight: bold;"&gt;localhost&lt;/span&gt;, not require SSL, and look like the following:&lt;br /&gt;&lt;br /&gt;http://localhost/contacts?WSDL&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-weight: bold;"&gt;FOR SOAP&lt;/span&gt; part of the command relates the &lt;span style="font-weight: bold;"&gt;GetContacts &lt;/span&gt;Method to the &lt;span style="font-weight: bold;"&gt;GetContacts&lt;/span&gt; Stored Procedure. Once you execute the command, take a peek at the &lt;span style="font-weight: bold;"&gt;Server Objects&lt;/span&gt; to see your &lt;span style="font-weight: bold;"&gt;HTTP Endpoint&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_gOWJOejMX_U/SdRYBhKKNdI/AAAAAAAAAJI/ZQQ1EmeQtRs/s1600-h/sqlserver2005endpoints.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 300px; height: 140px;" src="http://3.bp.blogspot.com/_gOWJOejMX_U/SdRYBhKKNdI/AAAAAAAAAJI/ZQQ1EmeQtRs/s400/sqlserver2005endpoints.jpg" alt="" id="BLOGGER_PHOTO_ID_5319973842935494098" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Fire Up Visual Studio 2005 to Consume the XML Web Service&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;At this point, you consume the &lt;span style="font-weight: bold;"&gt;XML Web Service&lt;/span&gt; like every other web service.  Create a Windows Application, called &lt;span style="font-weight: bold;"&gt;Native Http&lt;/span&gt;, drop a &lt;span style="font-weight: bold;"&gt;DataGridView &lt;/span&gt;on the form, and add a Web Reference specifying the following URL:&lt;br /&gt;&lt;br /&gt;http://localhost/contacts?WSDL&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gOWJOejMX_U/SdRY_4CPefI/AAAAAAAAAJQ/6Ojzj7LiEJ8/s1600-h/consumexmlwebservice.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 225px; height: 176px;" src="http://1.bp.blogspot.com/_gOWJOejMX_U/SdRY_4CPefI/AAAAAAAAAJQ/6Ojzj7LiEJ8/s400/consumexmlwebservice.jpg" alt="" id="BLOGGER_PHOTO_ID_5319974914228189682" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Leave the web reference name as &lt;span style="font-weight: bold;"&gt;localhost &lt;/span&gt;just so you can add the following code to the &lt;span style="font-weight: bold;"&gt;Form Load Event&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;localhost.AW_Contacts contacts = new Native_Http.localhost.AW_Contacts();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;contacts.Credentials = CredentialCache.DefaultCredentials;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;dataGridView1.DataSource = (contacts.GetContacts()[0] as DataSet).Tables[0];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Run the application and magically see the contacts appear in the &lt;span style="font-weight: bold;"&gt;DataGridView&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-7636848010766647867?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/7636848010766647867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=7636848010766647867' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/7636848010766647867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/7636848010766647867'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/04/native-xml-web-services-in-sql-server.html' title='Native XML Web Services in SQL Server 2005 - Creating HTTP Endpoints'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_gOWJOejMX_U/SdRWCP39D9I/AAAAAAAAAJA/Lx2hVaYQCsE/s72-c/adventureworksstoredprocedure.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-2859801203478047092</id><published>2009-03-10T18:20:00.005+05:30</published><updated>2009-03-10T18:32:34.350+05:30</updated><title type='text'>Service-Oriented Architecture (SOA) ... Some Basic Info</title><content type='html'>&lt;div&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;What is Service-Oriented Architecture (SOA)&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Service Oriented Architecture or SOA for short is a new architecture for the development of loosely coupled distributed applications. In fact service-oriented architecture is collection of many services in the network. These services communicate with each other and the communications involves data exchange &amp;amp; even service coordination. Earlier SOA was based on the DCOM or Object Request Brokers (ORBs). Nowadays SOA is based on the Web Services.&lt;br /&gt;&lt;br /&gt;Broadly SOA can be classified into two terms: Services and Connections.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;Services:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;----------&lt;/span&gt;&lt;br /&gt;A service is a function or some processing logic or business processing that is well-defined, self-contained, and does not depend on the context or state of other services. Example of Services are Loan Processing Services, which can be self-contained unit for process the Loan  Applications. Other example may be Weather Services, which can be used to get the weather information. Any application on the network can use the service of the Weather Service to get the weather information.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;Connections:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;---------------&lt;/span&gt;&lt;br /&gt;Connections means the link connecting these self-contained distributed services with each other, it enable client to Services communications. In case of Web services SOAP over HTTP is used to communicate the between services.&lt;br /&gt;&lt;br /&gt;The following figure is a typical example of the service-oriented architecture. It shows how a service consumer sends a service request to a service provider. After accepting the request, service provider send a message to the service consumer. In this case a service provider can also be a service consumer.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gOWJOejMX_U/SbZjRkq_NsI/AAAAAAAAAI4/HZxH5ZMPoCY/s1600-h/soaarchitectuire.gif"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 139px;" src="http://2.bp.blogspot.com/_gOWJOejMX_U/SbZjRkq_NsI/AAAAAAAAAI4/HZxH5ZMPoCY/s400/soaarchitectuire.gif" alt="" id="BLOGGER_PHOTO_ID_5311541964082984642" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;Different Technologies Used:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;---------------------------------&lt;/span&gt;&lt;br /&gt;SOA is much different from point-to-point architectures. SOA comprise loosely coupled, highly interoperable application services. These services can be developed in different development technologies (such as Java, .NET, C++, PERL, PHP), the software components become very reusable i.e. the same C# service may be used by a Java application and / or any other programming language. WSDL defines an standard,  which encapsulates / hides the vendor / language specific implementation from the calling client / service.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;Why SOA ?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;-----------&lt;/span&gt;&lt;br /&gt;SOA architecture enables seamless Enterprise Information Integration. Here are some of the Benefits of the Service&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Due to its platform independence, it allows companies to use the software and hardware of their choice.&lt;/li&gt;&lt;li&gt;There is no threat of vendor lock-in&lt;br /&gt;&lt;/li&gt;&lt;li&gt;SOA enables incremental development, deployment, and maintenance.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Companies can use the existing software (investments) and use SOA to build applications without replacing existing applications&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The training costs are low, so the available labor pool can be used for running the applications&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-2859801203478047092?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/2859801203478047092/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=2859801203478047092' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/2859801203478047092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/2859801203478047092'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/03/service-oriented-architecture-soa-basic.html' title='Service-Oriented Architecture (SOA) ... Some Basic Info'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_gOWJOejMX_U/SbZjRkq_NsI/AAAAAAAAAI4/HZxH5ZMPoCY/s72-c/soaarchitectuire.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-7106738065893883765</id><published>2009-02-11T10:50:00.002+05:30</published><updated>2009-02-11T10:55:35.212+05:30</updated><title type='text'>Getting Started on your First Web Page</title><content type='html'>&lt;div&gt;Creating your first web page can be a daunting and confusing task. Where do I  get started? What should I do? However, it does not have to be this way,  creating a web page can be a fun and rewarding experience if you just follow a  few simple guidelines, which we will outline for you here.&lt;br /&gt;&lt;br /&gt;The first thing that you should do when getting ready to construct your first  web page is to define it. What do you want your web page to do? Do not just  start constructing your page, really think about it. You should think about how  you want it to look, what information you want to provide to your prospective  customer in order to persuade him to buy your product or service rather than  going elsewhere.&lt;br /&gt;&lt;br /&gt;Be sure that you organize the page well, think of your Home Page like the Table  of Contents page in a book, it is there so that your customers know where to go  in your site for their particular needs, or just to familiarize themselves with  your product. Lastly, when defining your site you should do your research.  Always visit your competitions web site to see how they have organized their  site, so you can make yours better, whether it is just including more  information about your product, or simply making a better designed site.&lt;br /&gt;&lt;br /&gt;Now that you have given some serious thought to how you want your web site to  look, and what you want to include in it, you need to think of a name for it.  There are various approaches to finding the right name for your web site. The  first is to make the name logical, for instance, ****’s web site is ****.com.  Another approach is to make the name memorable so that your customers can type  it in without thought, the name does not have to be descriptive of the product  you sell, for example amazon.com sells books. Further, you should keep the name  as short as possible so that it is easy for your customers to type into the url  field.&lt;br /&gt;&lt;br /&gt;Now that you have your web page named and given some thought into how you want  it to look, here are some pointers for building your site. If you have pictures on your web page go over them first with a photo editing  program so that the customer’s browser does not have to crunch them. This will also  speed up the download speed of your page so that the customer can view quickly  without having to wait for large picture files to appear on the screen.&lt;br /&gt;&lt;br /&gt;One of the most annoying things for people surfing the web are pages that take a  long time to download. All those fancy graphics will not do you any good if  instead of waiting for the page to download the viewer closes his browser and  goes elsewhere, so consider going light on the pictures and heavy on the  information content.&lt;br /&gt;&lt;br /&gt;You should also put some serious thought into what color fonts you are going to  use, and the background color as well. When in doubt, remember that a white  background with black text has been successful for thousands of years!&lt;br /&gt;&lt;br /&gt;Your website should also be easy to navigate, all your links should be obvious  to the viewer, and should be self explanatory or have information about where  the link will take them. Try to keep the number of links you have low, the  viewer does not want to spend a lot of time waiting for links to download,  chances are, like you, he is pretty busy! Further, always link back to your  homepage in order to make navigating your web page easier for your potential  customers.&lt;br /&gt;&lt;br /&gt;Decide the number of pages you want to have inside of your site, and determine  logical titles for them. Think of any pictures that you might want to put on  each page and where you are going to put them in order to be most effective. You  should plan out your hyperlinks now, as it will make keeping track of them later  a lot easier and save you time trying to figure out why they are not working  properly. Decide where you want to put any buttons that you might create for  hyperlinks as well. Lastly write out any information content you will be putting  onto your web page in Microsoft Word first so you can detect any spelling errors  you might have made. You can cut and paste parts into your favorite editor later.&lt;br /&gt;&lt;br /&gt;So be sure to prepare before you start, think of the content you want to put in,  think about your links, think about your web site’s name, draw up an outline on  paper before you start constructing the page and most importantly&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color:red;"&gt;&lt;b&gt;“Plan Your Work and Work Your  Plan”&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-7106738065893883765?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/7106738065893883765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=7106738065893883765' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/7106738065893883765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/7106738065893883765'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/02/getting-started-on-your-first-web-page.html' title='Getting Started on your First Web Page'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-5102413494958016698</id><published>2009-02-05T09:23:00.016+05:30</published><updated>2009-03-05T19:25:58.104+05:30</updated><title type='text'>Practical difference between Interface and Abstract class</title><content type='html'>&lt;div&gt;&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;Interface&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Interface is used to collect similarities. Wherever we have to implement in the class means follow that similarities&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;Wherever we have to use (Real life scenario)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- Two person using same code but connection to the database methods only differ to each other. One person use sql based connection another one use oracle based connection. This type of scenario we can use Interface.&lt;br /&gt;- A human and a parrot can both whistle, however it would not make sense to represent Humans and Parrots as subclass of a Whistle class, rather they would most likely be subclasses of an Animal class (likely with intermediate classes), but would both implement the Whistle interface.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;What is Interface ?&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;The behavior of a class&lt;br /&gt;&lt;/li&gt;&lt;li&gt;All methods of an Interface are abstract methods.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;They cannot have bodies&lt;br /&gt;&lt;/li&gt;&lt;li&gt;You cannot create an instance from an interface&lt;br /&gt;&lt;/li&gt;&lt;li&gt;An interface can only be implemented&lt;br /&gt;&lt;/li&gt;&lt;li&gt;This is the concept of encapsulation&lt;br /&gt;&lt;/li&gt;&lt;li&gt;During runtime, actual object instance is associated with the interface type&lt;/li&gt;&lt;li&gt;It needs only the interface at the compile time&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Interface does not contain constructor&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Multiple inheritance  feature can be achieved through interface&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Cannot be versioned.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0); font-weight: bold;"&gt;Abstract Class&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;It is a class that contains one or more abstract methods&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It may contain constructor but interface does not contain constructor.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;In Interface all methods should be public but not in abstract class&lt;/li&gt;&lt;li&gt;Abstract class we can put sharable code&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Its not Possible to create instance of Abstract class&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It cannot be instantiated on it’s own, it must be inherited.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It can use One Overriding method&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It can specify members that must be implemented in inheriting classes&lt;br /&gt;&lt;/li&gt;&lt;li&gt;A class can inherit only one abstract class&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It enables us to place common instance behavior.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Offer versioning benefits.&lt;/li&gt;&lt;li&gt;Used for sharing common features among verious objects.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-5102413494958016698?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/5102413494958016698/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=5102413494958016698' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5102413494958016698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5102413494958016698'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/02/practical-difference-between-interface.html' title='Practical difference between Interface and Abstract class'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-6473665469398974395</id><published>2009-02-04T09:35:00.028+05:30</published><updated>2009-02-09T21:05:01.387+05:30</updated><title type='text'>Static Contructors in .Net</title><content type='html'>&lt;div style="font-weight: bold; color: rgb(153, 0, 0);"&gt;What is a static constructor?&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;As part of my job I conduct technical interviews for my company. One of the stock question in my interview is can constructors be declared static? Most of the time I get a blunt, no, as the answer. Even some argue that one cannot use the static word along with constructors. A very few who say yes are asked further questions on static constructors like what is the difference between a static constructors and normal constructors? For this also I have got lots of answers like static constructors can be called without creating an object, only static variables can be use etc. Some say static constructors are called only once and when I ask when is that once, People don’t have an answer. So I thought I will try to clear some confusion related to static constructors.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;Can constructors be declared Static?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;YES&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;What is the difference between a static constructor and normal constructors?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As we know Normal constructors are used to initialize class variables whereas static constructors are used to initialize class level static variables. Static constructors cannot access any other objects other than static as similar to static methods. Similar to static method, static constructors are class level and not instance level. Static constructors do not take any access modifiers, like public, private, protected etc. They also don’t take any arguments. Static constructors are called only once.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;Static constructors are called only once, when is that once?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Static constructors are called only once throughout the life time of the program, i.e. when the first instance of the class having static constructors is created or when a static member is accessed/used whichever happens first.Let me explain further, suppose you have a class called StaticConstructor with a static constructor as shown below.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;/***********Code*****************/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;namespace StaticConstructorDemo&lt;br /&gt;{&lt;br /&gt;class StaticConstructor&lt;br /&gt;{&lt;br /&gt;private static string someText;&lt;br /&gt;private static int counter;&lt;br /&gt;&lt;br /&gt;static StaticConstructor()&lt;br /&gt;{&lt;br /&gt;someText = "Static constructor executed. No of times: ";&lt;br /&gt;counter++;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void PrintSomeText()&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(someText + counter.ToString());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class MainClass&lt;br /&gt;{&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;StaticConstructor sc1 = new StaticConstructor();&lt;br /&gt;StaticConstructor sc2 = new StaticConstructor();&lt;br /&gt;StaticConstructor sc3 = new StaticConstructor();&lt;br /&gt;StaticConstructor.PrintSomeText();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;/***********End******************/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above code will print “Static constructor executed. No of times: 1”. The reason is static constructor is called only once when the first instance for the class is created i.e. when sc1 is created.If the above code inside the main method is rewritten like this&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;/***************Code**************/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;class MainClass&lt;br /&gt;{&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;StaticConstructor.PrintSomeText();&lt;br /&gt;StaticConstructor sc1 = new StaticConstructor();&lt;br /&gt;StaticConstructor sc2 = new StaticConstructor();&lt;br /&gt;&gt;StaticConstructor sc3 = new StaticConstructor();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;/***************End****************/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above code will have the same output as the previous code i.e. “&lt;span style="font-weight: bold;"&gt;Static constructor executed. No of times: 1&lt;/span&gt;”. Static constructor is called before the code inside the static method, &lt;span style="font-weight: bold;"&gt;PrintSomeText&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;()&lt;/span&gt;, is executed. As we know static methods can use static members and if a static constructor is not executed then there is every possibility of the system throwing “object reference not set to an instance” error. So static constructors are called before the first instance of the class is created or any static members are accessed/used.&lt;br /&gt;&lt;br /&gt;Hope from the above e.g. gives a clear idea...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-6473665469398974395?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/6473665469398974395/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=6473665469398974395' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/6473665469398974395'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/6473665469398974395'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2009/02/static-contructors-in-net.html' title='Static Contructors in .Net'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-6332188778197644617</id><published>2008-10-25T21:36:00.002+05:30</published><updated>2008-10-25T21:43:26.120+05:30</updated><title type='text'>The 10 Commandments of Great User Experience Design</title><content type='html'>&lt;div&gt;Starting a new software development project in the next little while?  Praying and hoping that it goes well?  Are you worrying about all the little software development intricacies like: Making sure you have a proper source control, ensuring you have a continuous integration environment, making sure you have great developers and making sure they are happy?  If you are, you probably haven’t remembered to pay attention to the most important part of the software development process. The User Interface and the User Experience.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;While there are literally hundreds of User Experience rules that you could follow, if you simply remember these 10 commandments, you should do just fine!  In fact, I recommend you print them out and put them in every developers office, or cubicle. Believe me..you will praise me in the long run.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Publish your application’s goals and objectives, your “mission statement” if you will.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The less choices you present to the user, the better.  Users get confused rather quickly.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;User Interface should remain consistent from screen to screen.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;No “Smart Menus” that change depending on how you use the application.  Users hate their application “changing” on them.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Keep the “Noise” to a minimum.  People don’t need to know about the business as usual messages.  Don’t annoy your user.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Avoid acronyms if at all possible. If you must use them, supply a descriptive message right beside it.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Your application must run lean and mean.  As pretty as your interface might be, if the software seems slow, no sale.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Let them explore the application, without fear they will cause a disaster. Undo, Redo, and History features might be a good idea.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Ensure your software works the first time its run.  Configurations can occur later, but out of the box, you should have intelligent defaults.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Have an easy way of allowing your users to provide feedback&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;div&gt;Every item on this list is very critical for the success of your project.  Make sure your software development team is always thinking about these things throughout your next project and you should be fairly happy with the outcome of the project.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I find that typically software developers will end up focusing solely on the architecture and technology of the application they working on, and leave the user experience piece as an afterthought.  This can have a huge impact on your timeline, and the happiness of the user’s of your application.  How many software developers out there have been on a project where you worked your buts off for months (if not years), and then went to release something to the users, and they where unimpressed with the application because the team didn’t put enough weight on the user experience?&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-6332188778197644617?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/6332188778197644617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=6332188778197644617' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/6332188778197644617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/6332188778197644617'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/10/10-commandments-of-great-user.html' title='The 10 Commandments of Great User Experience Design'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-5997823404271714425</id><published>2008-10-03T17:23:00.004+05:30</published><updated>2008-10-03T17:38:08.706+05:30</updated><title type='text'>Dictionary VS Hash Table</title><content type='html'>We all know how useful a hash table can be, but if you are using the &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;.NET Framework 2.0&lt;/span&gt; you should be using a &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;Dictionary &lt;/span&gt;&lt;/span&gt;instead. A dictionary and a hash table in .NET 2.0 are very similar but with 1 main difference, a dictionary is faster because it does not need to &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;box and unbox&lt;/span&gt;&lt;/span&gt; the data as a hash table would.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;I made a simple program to see just how much faster a dictionary is than a hash table. I ran the test 20 times for each data set and the results were close each time. A GUID as the key and a boolean as the data.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is the results of the last test for each dataset.&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'Times New Roman';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'Times New Roman';"&gt;&lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="174"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Time in Milliseconds for 100,000 keys&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="177"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Dictionary&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="147"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hash Table&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="173"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;Inserting&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="177"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;34.41264&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="148"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;76.0970&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="172"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;Reading&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="177"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;18.9005&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="149"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;31.1648&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="173"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;Deleting&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="176"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;21.2474&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="149"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;30.4655&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style="margin-top: 0px; "&gt; &lt;/p&gt;&lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="174"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;T&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;ime in Seconds for 10,000,000 keys&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="177"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Dictionary&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="147"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hash Table&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="173"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;Inserting&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="177"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;6.5704143&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="148"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;26.9096540&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="172"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;Reading&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="177"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;3.1362891&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="149"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;5.6670613&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top" width="173"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;Deleting&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="176"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;3.4623316&lt;/span&gt;&lt;/td&gt;&lt;td valign="top" width="149"&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;4.8830676&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style="margin-top: 0px; "&gt; &lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-5997823404271714425?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/5997823404271714425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=5997823404271714425' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5997823404271714425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5997823404271714425'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/10/dictionary-vs-hash-table.html' title='Dictionary VS Hash Table'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-8235117582370850078</id><published>2008-08-06T18:06:00.001+05:30</published><updated>2008-08-06T18:09:31.421+05:30</updated><title type='text'>Improving Performance with Connection Pooling</title><content type='html'>Opening a connection is a database-intensive task. It can be one of the slowest operations that you perform in an ASP.NET page. Furthermore, a database has a limited supply of connections, and each connection requires a certain amount of memory overhead (approximately 40 kilobytes per connection).&lt;br /&gt;&lt;br /&gt;If you plan to have hundreds of users hitting your Web site simultaneously, the process of opening a database connection for each user can have a severe impact on the performance of your Web site.&lt;br /&gt;&lt;br /&gt;Fortunately, you can safely ignore these bad warnings if you take advantage of connection pooling. When database connections are pooled, a set of connections is kept open so that they can be shared among multiple users. When you request a new connection, an active connection is removed from the pool. When you close the connection, the connection is placed back in the pool.&lt;br /&gt;&lt;br /&gt;Connection pooling is enabled for both OleDb and SqlClient connections by default.&lt;br /&gt;&lt;br /&gt;To take advantage of connection pooling, you must be careful to do two things in your ASP.NET pages. First, you must be careful to use the same exact connection string whenever you open a database connection. Only those connections opened with the same connection string can be placed in the same connection pool. For this reason you should place your connection string in the web.config file and retrieve it from this file whenever you need to open a connection.&lt;br /&gt;&lt;br /&gt;To take advantage of connection pooling in your ASP.NET pages, you also must be careful to explicitly close whatever connection you open as quickly as possible. If you do not explicitly close a connection with the Close() method, the connection is never added back to the connection pool.&lt;br /&gt;&lt;br /&gt;Connection pooling options that you can add to the SQL Server connection string:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;Connection Lifetime&lt;/strong&gt;&lt;/em&gt;— Destroys a connection after a certain number of seconds. The default value is 0, which indicates that connections should never be destroyed.&lt;/li&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;Connection Reset&lt;/strong&gt;&lt;/em&gt;— Indicates whether connections should be reset when they are returned to the pool. The default value is true.&lt;/li&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;Enlist&lt;/strong&gt;&lt;/em&gt;— Indicates whether a connection should be automatically enlisted in the current transaction context. The default value is true.&lt;/li&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;Max Pool Size&lt;/strong&gt;&lt;/em&gt;— The maximum number of connections allowed in a single connection pool. The default value is 100.&lt;/li&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;Min Pool Size&lt;/strong&gt;&lt;/em&gt;— The minimum number of connections allowed in a single connection pool. The default value is 0.&lt;/li&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;Pooling&lt;/strong&gt;&lt;/em&gt;— Determines whether connection pooling is enabled or disabled. The default value is true.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-8235117582370850078?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/8235117582370850078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=8235117582370850078' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8235117582370850078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8235117582370850078'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/08/improving-performance-with-connection.html' title='Improving Performance with Connection Pooling'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-8555283499455687180</id><published>2008-08-06T17:55:00.002+05:30</published><updated>2008-08-06T17:58:38.640+05:30</updated><title type='text'>SQL Injection Problem</title><content type='html'>SQL injection is a strategy often taken by hackers for attacking databases.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Example1:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;An ASP page asks the user for a name and a password, and then sends the following string to the database:&lt;br /&gt;&lt;strong&gt;SELECT FROM users WHERE username = 'whatever' AND password = 'mypassword'&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It seems safe, but it isn't. A user might enter something like this as her user name:&lt;br /&gt;&lt;strong&gt;' OR 1&gt;0 --&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When this is plugged into the SQL statement, the result looks like this:&lt;br /&gt;&lt;strong&gt;SELECT FROM users WHERE username = '' OR 1&gt;0 -- AND password = ''&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This injection comments out the password portion of the statement. It results in a list of all the names in the users table, so any user could get into your system.&lt;br /&gt;&lt;br /&gt;The easiest way to prevent this sort of injection is to parse the SQL string and remove any occurrences of "--" before passing the statement.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Example 2:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;You also have to beware of injections that contain semicolons because semicolons delimit SQL statements. Think about the implications of a user name like this:&lt;br /&gt;&lt;strong&gt;' OR 1&gt;0 ; DELETE Customers ; --&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There are numerous ways a malicious user might penetrate your system using SQL injection and various defenses, but the simplest approach is to avoid dynamic SQL. Instead, use stored procedures everywhere.&lt;br /&gt;&lt;br /&gt;Thanks to the way SQL passes parameters, injections such as those above will produce errors, and the stored procedure will not execute.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-8555283499455687180?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/8555283499455687180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=8555283499455687180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8555283499455687180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8555283499455687180'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/08/sql-injection-problem.html' title='SQL Injection Problem'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-5155455461868060674</id><published>2008-08-01T13:03:00.005+05:30</published><updated>2008-08-01T13:13:05.445+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sql-Server'/><title type='text'>Running an exe or program as SQL Server Job</title><content type='html'>This can be achieved by SQL Server Agent which is a Windows service to run scheduled adminstrative tasks or commonly know as jobs. SQL Server agent uses SQL Server t ostore job information. A job consists of steps which can be set using steps wizard during job scheduling.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Job Scheduling process&lt;/span&gt;:&lt;/strong&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Connect to the SQL Server where you want to schedule your job. &lt;/li&gt;&lt;li&gt;Check if SQL Server Agent (you can find it at the bottom most entity) is running, if not run it and set it to run automatic.&lt;/li&gt;&lt;li&gt;Right Click SQL Server Agent. Select New -&gt; Job. This will open a wizard to schedule a new job. &lt;/li&gt;&lt;li&gt;Select Steps from options given on the left side of wizard. This is the main place to set your exe\program as a running step. Give some name to this step, Select Operating System (cmd) for the Type and give the full path of exe in Text box for Command. Below is a sample step set up for running test.exe. &lt;/li&gt;&lt;li&gt;Now Select the job schedules option from left to set the frequency. Give some name to schedule, selection other options as shown in the figure below.&lt;img id="BLOGGER_PHOTO_ID_5229451050171169618" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_gOWJOejMX_U/SJK-Bfe--1I/AAAAAAAAAGQ/r8iMgLPobew/s400/JS_Steps1.png" border="0" /&gt;&lt;/li&gt;&lt;li&gt;If you want you can set optional Alerts and notification (using SQL notification services) to send out email in case any things fails, succeeds or at any specific event. &lt;img id="BLOGGER_PHOTO_ID_5229450801493586194" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_gOWJOejMX_U/SJK9zBFoMRI/AAAAAAAAAGI/ddmYGs-3oTc/s400/JS_Steps2.png" border="0" /&gt;&lt;/li&gt;&lt;li&gt;The targets option set the DB to look at or put data in. It should commonly be the localhost but you can set a remote SQL Server too here in case you have some DB interaction but then make sure that the account which you are using should have access to the remote server.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Your job is now scheduled to run everyday test.exe. just to make sure that everything run properly go to Agent -&gt; Jobs -&gt; NEW_JOB (the one you just created), right click NEW_JOB and select “start job at step”. This will run the job instantly for you and show the status if the job run successfully or failed. &lt;/p&gt;&lt;p&gt;So now you finally done.&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-5155455461868060674?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/5155455461868060674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=5155455461868060674' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5155455461868060674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5155455461868060674'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/08/running-exe-or-program-as-sql-server.html' title='Running an exe or program as SQL Server Job'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_gOWJOejMX_U/SJK-Bfe--1I/AAAAAAAAAGQ/r8iMgLPobew/s72-c/JS_Steps1.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-979411428018079418</id><published>2008-07-24T13:39:00.004+05:30</published><updated>2008-07-24T13:45:19.475+05:30</updated><title type='text'>Asp.Net Worker Process Recycling</title><content type='html'>If a Web application contains code that causes problems, and you cannot easily rewrite the code, it might be useful to limit the extent of the problems by periodically recycling the worker process that services the application. You can accomplish this by using what is known as Worker Process Recycling. Worker process recycling is the replacing of the instance of the application in memory. IIS 6.0 can automatically recycle worker processes by restarting the worker process, or worker processes, that are assigned to an application pool. This helps keep problematic applications running smoothly, and minimizes problems such as memory leaks. You can trigger the recycling of the worker processes assigned to an application pool by using worker process recycling methods that are based on elapsed time, the number of Hypertext Transfer Protocol (HTTP) requests, a set time of day, and two kinds of memory consumption, in addition to recycling on demand.&lt;br /&gt;&lt;br /&gt;To configure all the above settings, go to the Properties window of the application pool in which your Web application is running using the IIS manager. Using the &lt;span style="color:#990000;"&gt;Recycling&lt;/span&gt;, &lt;span style="color:#990000;"&gt;Performance&lt;/span&gt;, and &lt;span style="color:#990000;"&gt;Health&lt;/span&gt; tabs in the Properties window, you can specify values for the above settings. Navigating to the Performance tab in the Properties dialog box of the &lt;strong&gt;DemoAppPool&lt;/strong&gt; results in the following output.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_gOWJOejMX_U/SIg5Wq1HQSI/AAAAAAAAAFo/UaNdY0Os-KI/s1600-h/IIS6P29.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5226490429180428578" style="CURSOR: hand" alt="" src="http://bp3.blogger.com/_gOWJOejMX_U/SIg5Wq1HQSI/AAAAAAAAAFo/UaNdY0Os-KI/s400/IIS6P29.gif" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;When you set the recycling of worker processes using IIS manager, you also need to take the state management strategy of your ASP.NET application into consideration. Because every time the worker process is recycled, the ASP.NET state information will be lost rendering the application in an invalid state. One alternative to overcome this issue is to maintain state data external to the worker process, such as in a database. However, moving data to an external database to allow recycling can affect server performance in the following two ways:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Performance is reduced because of the added data management that is needed to move the data between the application and the database.&lt;/li&gt;&lt;li&gt;Recycling flushes any in-process data caches, so the caches need to be rebuilt.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you have an application pool with applications that depend on state data, you must decide whether or not to recycle the worker processes that are assigned to that application pool. If you store state in the same process as that of IIS, and you don't want the state information to be lost, you must not recycle a worker process using the application pool configuration settings.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-979411428018079418?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/979411428018079418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=979411428018079418' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/979411428018079418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/979411428018079418'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/07/aspnet-worker-process-recycling.html' title='Asp.Net Worker Process Recycling'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_gOWJOejMX_U/SIg5Wq1HQSI/AAAAAAAAAFo/UaNdY0Os-KI/s72-c/IIS6P29.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-2075993675735941821</id><published>2008-07-22T11:32:00.008+05:30</published><updated>2008-07-22T12:15:39.559+05:30</updated><title type='text'>Encryption Sections of Web.config</title><content type='html'>&lt;strong&gt;Configuration files&lt;/strong&gt; are just great ; they let you configure the website .It's a great place to store the information which you are going to be using throughout the application and which is not changing.&lt;br /&gt;&lt;br /&gt;You can easily encrypt sections of web.config in ASP.NET 2.0. In the code below I have encrypted the ConnectionStrings section of web.config.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;ConfigurationSection configSection = config.GetSection("connectionStrings");&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;if (configSection.SectionInformation.IsProtected)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;{ &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;configSection.SectionInformation.UnprotectSection(); &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;config.Save();&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;}&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;else&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;{ &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;config.Save();&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;}&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;.NET Framework 2.0 introduces a protected configuration feature that you can use to encrypt sensitive configuration file data by using a command line tool. The following two protected configuration providers are provided although you can also implement custom providers.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;RSAProtectedConfigurationProvider&lt;/span&gt; :&lt;/strong&gt; This is the default provider and uses the RSA public key encryption to encrypt and decrypt data.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;DPAPIProtectedConfigurationProvider&lt;/span&gt; :&lt;/strong&gt; This provider uses the Windows Data Protection API (DPAPI) to encrypt and decrypt data.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;You can also writing connection string dynamically:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;ConnectionStringsSection conSection = (ConnectionStringsSection)config.GetSection("connectionStrings");&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;conSection.ConnectionStrings["SQLConnectionString"].ConnectionString = "NewConnectionString";&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;config.Save(); &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;[Please note that when you write to a web.config file the application restarts which means all the session and application variables are lost.]&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-2075993675735941821?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/2075993675735941821/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=2075993675735941821' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/2075993675735941821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/2075993675735941821'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/07/encryption-sections-of-webconfig-in.html' title='Encryption Sections of Web.config'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-4639424345110514875</id><published>2008-07-08T11:33:00.004+05:30</published><updated>2008-07-08T15:39:44.170+05:30</updated><title type='text'>New Features of VS-2008</title><content type='html'>Historically, Microsoft has introduced a new Visual Studio product to accompany a new Framework version, they did that with Framework versions 1.0 - 2.0 as follows:&lt;br /&gt;&lt;br /&gt;&gt;&gt; Framework v 1.0 --- VS .NET 2002&lt;br /&gt;&gt;&gt; Framework v 1.1 --- VS .NET 2003&lt;br /&gt;&gt;&gt; Framework v 2.0 --- VS .NET 2005&lt;br /&gt;&lt;br /&gt;Obviously, the 2.0 Framework represented major modifications to the coresoftware (new compilers a new CLR, etc) and so, of course there were bugs.There have since been service packs for both the 2.0 Framework and VS 2005 to address these issues.&lt;br /&gt;&lt;br /&gt;Then, Microsoft did something a little different, they introduced some new.NET technologies, but instead of creating a *whole* new Framework with newcompilers, a new CLR, etc., they made a new Framework version that just hadwhat was necessary to run the new features (Windows CommunicationFoundation, Windows Workflow, Windows Presentation Foundation) and called that Framework version 3.0. Instead of making a new version of VisualStudio to do along with that, Microsoft created a plethora of add-in's to VS2005 that would make it work with the new 3.0 stuff.&lt;br /&gt;&lt;br /&gt;Now, the latest version of the Framework is 3.5 (adds additional support forLINQ and Ajax on top of WF, WPF, and WCF). For this new release (now thatmost of the bugs have been worked out, Microsoft has released Visual Studio2008, which works against the 3.5 Framework (there are no add-in's andservice packs for this - - yet).&lt;br /&gt;&lt;br /&gt;Essentially, VS 2008 gives you access to all of the new Framework stuff AND is really VS 2005 with all the bugs worked out. It is considered a very stable product and has the advantage of making all the latest .NET technologies rolled up into it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Following are the new features that Microsoft has introduced in the VS2008. &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;LINQ Support&lt;/li&gt;&lt;li&gt;Expression Blend Support&lt;/li&gt;&lt;li&gt;Windows Presentation Foundation&lt;/li&gt;&lt;li&gt;VS 2008 Multi-Targeting Support&lt;/li&gt;&lt;li&gt;Inbuilt AJAX support for ASP.NET&lt;/li&gt;&lt;li&gt;JavaScript Debugging Support&lt;/li&gt;&lt;li&gt;Nested Master Page Support&lt;/li&gt;&lt;li&gt;LINQ Intellisense and Javascript Intellisense support for silverlight applications&lt;/li&gt;&lt;li&gt;Intellisense Support&lt;/li&gt;&lt;li&gt;Intellisense Filtering&lt;/li&gt;&lt;li&gt;Intellisense Box display position&lt;/li&gt;&lt;li&gt;Organize Imports or Usings&lt;/li&gt;&lt;li&gt;Visual Studio 2008 Split View&lt;/li&gt;&lt;li&gt;HTML JavaScript warnings, not as errors&lt;/li&gt;&lt;li&gt;Debugging .NET Framework Library Source Code&lt;/li&gt;&lt;li&gt;In built Silverlight Library&lt;/li&gt;&lt;li&gt;Visual Studio LINQ Designer&lt;/li&gt;&lt;li&gt;Inbuilt C++ SDK&lt;/li&gt;&lt;li&gt;Microsoft Popfly Support&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To get detail information about these features &lt;strong&gt;&lt;a href="http://msdotnetsupport.blogspot.com/2007/11/22-new-features-of-visual-studio-2008.html"&gt;Chick Here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-4639424345110514875?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/4639424345110514875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=4639424345110514875' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/4639424345110514875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/4639424345110514875'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/07/new-features-of-vs-2008.html' title='New Features of VS-2008'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-8891506245940715487</id><published>2008-06-26T15:15:00.006+05:30</published><updated>2008-06-26T15:32:54.869+05:30</updated><title type='text'>Spy on Your Web Host: Checking Uptime</title><content type='html'>Your host promises 99.999% uptime, but are they really delivering? Unless you're either checking every couple of seconds, or dishing out on some monitoring service, you really don't have much of an idea.&lt;br /&gt;&lt;br /&gt;ASP.NET Web pages served up through IIS are delivered through an ASP.NET "worker process" (&lt;strong&gt;&lt;span style="color:#000099;"&gt;aspnet_wp.exe&lt;/span&gt;&lt;/strong&gt;). It's this file that executes your code and puts all the ASP.NET pieces together. If we could access this worker process, we may be able to look at how long it had been running, its current state—and perhaps even a history, showing previous instantiations of the worker process.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Dim strReport As String&lt;br /&gt;Dim objInfo As ProcessInfo = _&lt;br /&gt;ProcessModelInfo.GetCurrentProcessInfo&lt;br /&gt;' &lt;span style="color:#000000;"&gt;Get time information&lt;br /&gt;&lt;/span&gt;strReport = "ASP.NET was started at " &amp;amp; objInfo.StartTime.ToString &amp;amp; ". " &amp;amp; "It has been running for " &amp;amp; objInfo.Age.Days &amp;amp; " days, " &amp;amp; objInfo.Age.Hours &amp;amp; " hours and " &amp;amp; objInfo.Age.Minutes &amp;amp; " minutes. "&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Response.Write(strReport)&lt;br /&gt;' &lt;span style="color:#000000;"&gt;Get other info&lt;/span&gt;&lt;br /&gt;strReport = "The process ID is " &amp;amp; objInfo.ProcessID &amp;amp; ". " &amp;amp; "Current status is " &amp;amp; objInfo.Status.ToString &amp;amp; ". " &amp;amp; "Peak memory used was " &amp;amp; objInfo.PeakMemoryUsed &amp;amp; ". " &amp;amp; "Request count is currently " &amp;amp; objInfo.RequestCount &amp;amp; "."&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Response.Write(strReport)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;What we're doing here is retrieving a &lt;strong&gt;ProcessInfo&lt;/strong&gt; object containing information about the current worker process. This is then formulated into a string using key properties and spurted out to the user, through &lt;strong&gt;Response.Write&lt;/strong&gt;. Try it out—you'll be given an instant server status report.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The &lt;strong&gt;ProcessModelInfo&lt;/strong&gt; class also has a &lt;strong&gt;GetHistory&lt;/strong&gt; method, allowing you to retrieve information about previous instances of the &lt;strong&gt;aspnet_wp.exe&lt;/strong&gt; process. It returns an array of &lt;strong&gt;ProcessInfo&lt;/strong&gt; objects. Either use a For...Next loop to retrieve this information, or bind direct to a Grid.&lt;br /&gt;&lt;br /&gt;There's also a technique for retrieving the amount of time your actual server has been running (not just the ASP.NET worker process). Simply nab the TickCount from the Environment class, which lists the number of milliseconds the machine has been running. After that, either perform a few simple calculations—or, slightly easier, convert it into a period of time (a TimeSpan object), then retrieve the appropriate properties. Here's my snippet of code that does exactly that:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;Dim tsAge As TimeSpan = TimeSpan.FromMilliseconds(Environment.TickCount)&lt;br /&gt;Dim intDaysUp As Integer = tsAge.Days&lt;br /&gt;Dim intHoursUp As Integer = tsAge.Hours&lt;br /&gt;Dim intMinsUp As Integer = tsAge.Minutes&lt;br /&gt;Response.Write("The server has been up " &amp;amp; intDaysUp &amp;amp; " days, " &amp;amp; intHoursUp &amp;amp; " hours and " &amp;amp; intMinsUp &amp;amp; " minutes.")&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#006600;"&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;a href="http://bp3.blogger.com/_gOWJOejMX_U/SGNni9-DYDI/AAAAAAAAAFg/BHcXQmpP1zI/s1600-h/ASPNET0501.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5216126643873210418" style="WIDTH: 288px; CURSOR: hand; HEIGHT: 193px" height="210" alt="" src="http://bp3.blogger.com/_gOWJOejMX_U/SGNni9-DYDI/AAAAAAAAAFg/BHcXQmpP1zI/s400/ASPNET0501.gif" width="382" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Caption: ASP.NET only been running for 13 minutes? Sounds dodgy. Change your host.&lt;/span&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-8891506245940715487?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/8891506245940715487/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=8891506245940715487' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8891506245940715487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8891506245940715487'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/spy-on-your-web-host-checking-uptime-in.html' title='Spy on Your Web Host: Checking Uptime'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_gOWJOejMX_U/SGNni9-DYDI/AAAAAAAAAFg/BHcXQmpP1zI/s72-c/ASPNET0501.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-473808432517782999</id><published>2008-06-26T13:58:00.003+05:30</published><updated>2008-06-26T14:16:55.079+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips / Tricks'/><title type='text'>.Net Tips and Tricks (Part -V)</title><content type='html'>&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Force Button Click by Pressing Enter Key&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Sometimes, you will notice, that, in an ASP.Net form, depending on the circumstances, pressing the '&lt;strong&gt;Enter&lt;/strong&gt;' key to submit the form does not work.To force this to happen for a particular button on your page, just put this in the Page_Load routine:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Page.RegisterHiddenField("__EVENTTARGET", "button1")&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Then, change 'button1' to the ID of your particular button. Understand, of course, if your cursor is inside of a MultiLine textbox, the default action of the enter key is to create a new line in the textbox, so, if this basically works anywhere outside of that scenario.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Select Specific DropDownList Item&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;With a dropdown list - you can dynamically select items in the list with a sort of 'built-in' find routine.To select a certain item, based on the Value of the item in the list:&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByValue(YourValueHere))&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;To select a certain item, based on the Text of the item in the list:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByText("YourTextHere"))&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;OR - you can do it this way:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;DropDownList.Items.FindByText("TextYouAreLookingFor").Selected = true&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;or, using the value of the item&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;DropDownList.Items.FindByValue("ValueYouAreLookingFor").Selected = true&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;ASP.Net Server Controls Not Showing on pages&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;It's possible that ASP.Net is not registered correctly on your system.Try running aspnet_regiis from the command prompt.Here's the default location: &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;C:\[Windows Folder]\Microsoft.NET\Framework\[ASP.Net Version#]\ aspnet_regiis.exe -i&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Windows Server 2003, you must use &lt;strong&gt;&lt;span style="color:#ff0000;"&gt;aspnet_regiis -i -enable&lt;/span&gt;&lt;/strong&gt;. This is because of the "Web Service Extensions" feature in IIS 6&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;em&gt;(if you install VS.NET or the framework without IIS installed, and then go back in and install IIS afterwards, you have to re-register so that ASP.NET 'hooks' into IIS properly.")&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;em&gt;&lt;/em&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Make a Horizontal Rule Visible or Invisible&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you want to refer to a Horizontal rule in coding, to make it visible or invisible, just use the runat=Server designation, along with an ID and you're ready to go:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;[hr id="rule" visible="true" runat="server"/]&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Select Specific ListBox Item&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you don't know the exact index number in the list of listbox items (listbox1.selectedindex=x), then you can find an item and select it by using the Value of the item:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;ListBox1.Items.FindByValue(MyValue).Selected = true&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you don't know theValue of the item, but you know the text, you can find and select the item using the Text of the item:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;ListBox1.Items.FindByText("TextYouAreLookingFor").Selected = true&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;List all Tables in an MS Access Database&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;However you decide to display the list of tables from a particular MS Access Database, just create your connection and display code in the same way you would normally do it.&lt;br /&gt;The only change would be your SQL statement. Structure it this way:&lt;br /&gt;&lt;strong&gt;SELECT [Name] FROM MSysObjects WHERE [Type] = 1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;Javascript - Delete Textbox text onFocus&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Let's say you have an ASP.Net TextBox server control that has the text:&lt;br /&gt;"&lt;em&gt;Enter Fax #&lt;/em&gt;"&lt;br /&gt;Then, you want the text to disappear when the user clicks inside the TextBox - - here is a very simple solution.&lt;br /&gt;In the Page_Load event, put:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;txtFax.Attributes("OnFocus")="document.formName.txtFax.value='';"&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-473808432517782999?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/473808432517782999/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=473808432517782999' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/473808432517782999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/473808432517782999'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/net-tips-and-tricks-part-v.html' title='.Net Tips and Tricks (Part -V)'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-5611815000195599564</id><published>2008-06-26T10:35:00.009+05:30</published><updated>2008-07-14T13:28:32.695+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips / Tricks'/><title type='text'>.Net Tips and Tricks (Part -IV)</title><content type='html'>&lt;strong&gt;&lt;span style="color:#990000;"&gt;Numeric-Only Textboxes&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you haven't heard of the built in ASP.Net Validator controls, it's time to learn. There are several, but, for this case, you would use a Regular Expression Validator. The Regular Expression for making sure only numeric data is inserted into the textbox is:&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;^([0-9]*\d*\d{1}?\d*)$&lt;br /&gt;&lt;/span&gt;You'd use it in a Regular Expression Validator, in conjunction with an ASP.Net Textbox, like this:&lt;br /&gt;&lt;span style="color:#006600;"&gt;[asp:TextBox id="txtNumber" Runat="server" /] &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;[asp:RegularExpressionValidator ID="vldNumber" ControlToValidate="txtNumber" Display="Dynamic" ErrorMessage="Not a number" ValidationExpression="(^([0-9]*\d*\d{1}?\d*)$)" Runat="server"/] &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Get the Last Write Time of File&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;In order to get the last time a file (like an MS Access database, or any other file) was written, you can do the following: Use/import the System.IO namespace, then&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;Dim sFileWriteTime as File&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;Label1.Text=sFileWriteTime.GetLastWriteTime(Server.MapPath ("/path/yourMDB.mdb"))&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Find Specific Field in DataSet&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Sometimes, when we fill DataSet from a Query, we need to get a particular item in one of the DataTable fields for later use. In order to find a particular item, we can use the field name from the database like this, and assign it to a variable:&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;sOrderNum = Ds.Tables[0].Rows[0]["ordnum"]&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;We'd just need to have created the variable globally, then, we can use that variable (sOrderNum) easily, anywhere in the page now.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;MS Access Update Problems with Parameters&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;A very common problem, using parameters with MS Access, in ASP.Net is that it does not update the database, but also, it doesn't return an error. The problem, most likely, is that the parameters are not in the same order as the SQL statement. Remember to put the list of parameters in the same order as they hold sql statement, including any parameters in the Clause(s) at the end of the statement.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Check for Null before inserting into Database&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Here's a function to ensure a Null value gets inserted into the database.&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Function CheckForNULL(strStringToCheck)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;if len(trim(strStringToCheck)) = 0 then &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;CheckForNULL =dbNull.Value &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;else &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;CheckForNULL = strStringToCheck&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;end if &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;end function&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you have a DateTime field, without a function like this, a default date will be entered (ie 1/1/1900 12:00:00 AM), instead of null, when your insert is executed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;How to Align text in the TextBox Server Control&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;First, in your StyleSheet (either inline or external), create a class.&lt;br /&gt;For the sake of this tip, we'll call it '&lt;strong&gt;txtAlign&lt;/strong&gt;', but the name doesn't matter.&lt;br /&gt;Then, add your alignment needs to the class: &lt;span style="color:#ff0000;"&gt;text-align: right&lt;/span&gt;;&lt;br /&gt;Lastly, inside the TextBox Server Control on your page, use the CSSClass property of the textbox to assign the CSS value to the textbox:&lt;span style="color:#ff0000;"&gt;CSSClass="txtAlign&lt;/span&gt;"&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;How to set focus on an ASP.Net TextBox Control when the page loads&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Two things:&lt;br /&gt;1. Give your BODY Tag and ID and include 'Runat=Server'(like - - [body id="bdyMain" runat="Server"])&lt;br /&gt;2. In the Page_Load event:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;if not Page.IsPostBack then &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;bdyMain.attributes("onload")="document.form1.TextBox1.focus();" &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;end if &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;How To work with TimeSpan Class&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Dim adate As DateTime = DateTime.Parse("06/24/2008")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Dim bdate As DateTime = DateTime.Parse("06/28/2008")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Dim ts As New TimeSpan(bdate.Ticks - adate.Ticks)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Response.Write(ts.TotalDays &amp;amp; " ")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Response.Write(ts.TotalHours &amp;amp; ":" &amp;amp; ts.TotalMinutes &amp;amp; ":" &amp;amp; ts.TotalSeconds &amp;amp; ":" &amp;amp; ts.TotalMilliseconds)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;How to Compare Time&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Dim t1 As String = DateTime.Parse("4:30 PM").ToString("t")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Dim t2 As String = DateTime.Now.ToString("t")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;If DateTime.Compare(t1, t2) &lt;&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Response.Write(t1.ToString() &amp;amp; " is &lt;&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Else &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;Response.Write(t1.ToString() &amp;amp; " is &gt; than " &amp;amp; t2.ToString())&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;End If&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Loop through all the textbox controls on the ASP.NET Page&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;You can loop through all the textbox controls on ASP.NET Page using this code.&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#006600;"&gt;private void LoopTextBoxes (Control parent) &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;foreach (Control c in parent.Controls) &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;TextBox tb = c as TextBox; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;span style="color:#006600;"&gt;&lt;span style="color:#006600;"&gt;if (tb != null) &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;//Do something with the TextBox&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;And you can start the looping by calling:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;LoopTextBoxes(Page);&lt;/strong&gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Disabling a Button Until Processing is Complete&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Here's the scenario - let's say you have an Insert subroutine, called '&lt;strong&gt;doInsert&lt;/strong&gt;'. You want to immediately disable the &lt;strong&gt;Submit&lt;/strong&gt; button, so that the end-user won't click it multiple times, therefore, submitting the same data multiple times.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;For this, use a regular HTML button, including a Runat="server" and an 'OnServerClick' event designation - like this:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;[INPUT id="Button1" onclick="document.form1.Button1.disabled=true;" type="button" value="Submit - Insert Data" name="Button1" runat="server" onserverclick="doInsert"]&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Then, in the very last line of the '&lt;strong&gt;doInsert'&lt;/strong&gt; subroutine, add this line:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;Button1.Disabled=false&lt;/strong&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-5611815000195599564?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/5611815000195599564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=5611815000195599564' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5611815000195599564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5611815000195599564'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/net-tips-and-tricks-part-iv.html' title='.Net Tips and Tricks (Part -IV)'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-3608515843142056919</id><published>2008-06-25T11:38:00.009+05:30</published><updated>2008-06-25T12:48:25.114+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips / Tricks'/><title type='text'>.Net Tips and Tricks (Part -III)</title><content type='html'>&lt;strong&gt;&lt;span style="color:#990000;"&gt;Gridview Sorting - Only Certain Columns&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;To allow sorting on only certain columns in a Gridview, set the AllowSorting Property to True, but, for those columns you do NOT want to be sorted, using BoundFields, or TemplateFields, remove the SortExpression property.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Why is my button event firing twice?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;The most common reason for double click events are situations in which the button markup includes an OnClick event, AND, the event handler (in your code) also has a 'Handles' statement, at the end of the event handler signature - -&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Gridview Paging without a Datasource Control&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you are populating your Gridview with code, and not through a DataSource control, to be able to add paging, merely add a PageIndexChanging event for the Gridview:&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;Protected Sub YourGridview_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)&lt;/strong&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;YourGridview.PageIndex = e.NewPageIndex &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;YourGridview.DataBind()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;End Sub&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Templates - the Answer to a Consistent Look and Feel&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Let's say you have a company, and you have several websites within that company, but you need to have a consistent look and feel for each of them.Create a website with the bare minimum, that you want to look the same in all websites, with Themes, navigation, and whatever else you want.&lt;br /&gt;Then, in VS.Net 2005, click File/Export Template. That's all there is to it. The next time you want a website to look like this template, just click File/New, and choose your template (which will be under 'My Templates'&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Using Response object in a Class&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you try this, straight away, you will probably receive an error message, telling you the Response object is not available in this context.&lt;br /&gt;So, in order to get rid of the error message, &lt;span style="color:#006600;"&gt;&lt;strong&gt;Import System.Web&lt;/strong&gt;&lt;/span&gt;, and then, change :&lt;br /&gt;Response.(whatever)&lt;br /&gt;to&lt;br /&gt;HttpContext.Current.Response.(whatever)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Add 'Select' feature to existing Button/Imagebutton in TemplateField&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you already have any kind of button, whether it be a plain button, LinkButton, or Imagebutton, in a TemplateField, within a GridView, you can add 'Select' features to it, just as if you had added a 'Select' column.&lt;br /&gt;All you need to do is add 'Select' to the CommandName property. Then, anything you could do with the Select CommandField, you can do with your own TemplateField.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Force TextBox Values to Capital Letters whenever user types(Simple way)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Create a css class with the following definition and apply the cssclass to the Textbox.&lt;br /&gt;.MakeCapsStyle{text-transform: uppercase;}&lt;br /&gt;[asp:textbox id="id" runat="server" cssclass="MakeCapsStyle" /]&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Two Databound Fields in Gridview column&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Boundfields are great in the Gridview, but they do have their limitations. One is that it only has room for one bound field. So, what do you do when you want two or data fields (like First and Last names) returned to the same column?&lt;br /&gt;Turn the BoundField into a TemplateField, with a label in it:&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;[asp:TemplateField]&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;[ItemTemplate]&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;[asp:Label ID="lblname" runat="server" Text='[%# Eval("Lname") +", "+ Eval("Fname") %' /]&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;[/ItemTemplate]&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;[/asp:TemplateField]&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Quick and Dirty - Clear Gridview&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you need to completely clear a Gridview quickly, create a sub like this:&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;Protected Sub ClearGrid(ByVal gv As GridView)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;gv.DataSource = Nothing gv.DataSourceID = Nothing gv.DataBind()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;End Sub&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;Then, you can use it by using your Gridview ID:&lt;br /&gt;&lt;span style="color:#006600;"&gt;ClearGrid("YourGridViewID")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Nest Master pages easily&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Let's say your scenario is that you want a Master page for your business's website. However, inside that 'shell', you also want a certain design for each department of the business. All you need to do, is create the second 'Department' Master page. Then, inside the Master Directive, include a reference back to the Business Master:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;[%@ Master Language="VB" MasterPageFile="~/Business.master" .....&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Also, be sure to use different ContentPlaceholder ids, and remember the one caveat - if you're using Nested Masters inside VS.Net 2005, you'll need to only use the html view, since the design view does not support nesting master pages.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Server.Transfer Vs. Response.Redirect&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Server.Transfer&lt;/span&gt;&lt;/strong&gt; processes the page from one page directly to the next page without making a round-trip back to the client's browser. This way is faster, with a little less overhead on the server. However, it does NOT update the clients url history list or current url.&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;Response.Redirect&lt;/span&gt;&lt;/strong&gt;, as expected, is used to redirect the user's browser to another page or site. It DOES perform a trip back to the client where the client's browser is actually redirected to the new page. The browser history list IS updated to reflect the new address.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;DataFormatString does not work in Boundfield&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;The new Gridview control in v2.0 take over the formatting of items in the BoundFields. Therefore, using a DataFormatString by itself won't work. To change the format to, let's say, Currency, we'd need to, not only set the DataFormatString="{0:c}", but we'd need to make use of the HTMLEncode property, setting it to 'False'&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Assigning ASP.Net variables to Javascript&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;em&gt;Scenario&lt;/em&gt;:&lt;/span&gt;You have an ASP.Net variable called sCustState, that you also want to use in a Javascript function. Here's how you do make it work, within Javascript, assigning it to a Javascript variable.&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;var sstate; &lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;sstate='&lt;%#sCustState %&gt;';&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Adding a Print Button with Javascript&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;If you'd like to use an ASP.Net button for printing, all you need to do is :&lt;br /&gt;Add this line to the Page_Load event&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;btnPrint.Attributes("onClick") ="javascript:window.print();"&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;Add a button to the page called 'btnPrint'.&lt;br /&gt;Technically, that's it, but, let's say you want to do something a little fancier, using DotNet. Then, add a subroutine (let's call it 'DoPrint'):&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;Sub doPrint(Source as Object, E as EventArgs) &lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;lblResults.visible="True"&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;lblResults.text="Page has successfully been sent to the printer!" &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#006600;"&gt;&lt;strong&gt;End Sub&lt;/strong&gt;&lt;/span&gt; &lt;span style="color:#006600;"&gt;&lt;br /&gt;&lt;/span&gt;Then, add a direction to this sub, in the button's tag:&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color:#006600;"&gt;onServerclick="doPrint" &lt;/span&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-3608515843142056919?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/3608515843142056919/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=3608515843142056919' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/3608515843142056919'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/3608515843142056919'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/net-tips-and-tricks-part-iii.html' title='.Net Tips and Tricks (Part -III)'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-8472282312513244132</id><published>2008-06-23T15:19:00.009+05:30</published><updated>2009-05-06T11:46:49.452+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips / Tricks'/><title type='text'>Performance Tips for ASP.NET Applications</title><content type='html'>&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Cache Aggressively&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;When designing an app using ASP.NET, make sure you design with an eye on caching. On server versions of the OS, you have a lot of options for tweaking the use of caches on the server and client side. There are several features and tools in ASP that you can make use of to gain performance.&lt;br /&gt;Output Caching—Stores the static result of an ASP request. Specified using the @% OutputCache % directive:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Duration—Time item exists in the cache&lt;/li&gt;&lt;li&gt;VaryByParam—Varies cache entries by Get/Post params&lt;/li&gt;&lt;li&gt;VaryByHeader—Varies cache entries by Http header&lt;/li&gt;&lt;li&gt;VaryByCustom—Varies cache entries by browser&lt;/li&gt;&lt;li&gt;Override to vary by whatever you want&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Fragment Caching—When it is not possible to store an entire page (privacy, personalization, dynamic content), you can use fragment caching to store parts of it for quicker retrieval later.&lt;br /&gt;a) VaryByControl—Varies the cached items by values of a control.&lt;/p&gt;&lt;p&gt;Cache API—Provides extremely fine granularity for caching by keeping a hashtable of cached objects in memory (System.web.UI.caching). It also:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Includes Dependencies (key, file, time)&lt;/li&gt;&lt;li&gt;Automatically expires unused items&lt;/li&gt;&lt;li&gt;Supports Callbacks&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Caching intelligently can give you excellent performance, and it's important to think about what kind of caching you need. Imagine a complex e-commerce site with several static pages for login, and then a slew of dynamically-generated pages containing images and text. You might want to use Output Caching for those login pages, and then Fragment Caching for the dynamic pages. A toolbar, for example, could be cached as a fragment. For even better performance, you could cache commonly used images and boilerplate text that appear frequently on the site using the Cache API.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Use Session State Only If You Need To&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;One extremely powerful feature of ASP.NET is its ability to store session state for users, such as a shopping cart on an e-commerce site or a browser history. Since this is on by default, you pay the cost in memory even if you don't use it. If you're not using Session State, turn it off and save yourself the overhead by adding @% EnabledSessionState = false % to your asp.&lt;/p&gt;&lt;p&gt;For pages that only read session state, you can choose EnabledSessionState=readonly. This carries less overhead than full read/write session state, and is useful when you need only part of the functionality and don't want to pay for the write capabilities.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Use View State Only If You Need To&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;An example of View State might be a long form that users must fill out: if they click Back in their browser and then return, the form will remain filled. When this functionality isn't used, this state eats up memory and performance. Perhaps the largest performance drain here is that a round-trip signal must be sent across the network each time the page is loaded to update and verify the cache. Since it is on by default, you will need to specify that you do not want to use View State with @% EnabledViewState = false %.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Batch Compile&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Always batch compile before deploying a large page into the Web. This can be initiated by doing one request to a page per directory and waiting until the CPU idles again. This prevents the Web server from being bogged down with compilations while also trying to serve out pages.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Avoid the Autoeventwireup Feature&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Instead of relying on autoeventwireup, override the events from Page. For example, instead of writing a Page_Load() method, try overloading the public void OnLoad() method. This allows the run time from having to do a CreateDelegate() for every page.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;protected override void OnLoad(EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;      Response.Write("Page Load method Over ridden");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Use the Optimal Authentication Procedure&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;There are several different ways to authenticate a user and some of more expensive than others (in order of increasing cost: None, Windows, Forms, Passport). Make sure you use the cheapest one that best fits your needs.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Use Stored Procedures Whenever Possible&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Stored procedures are highly optimized tools that result in excellent performance when used effectively. Set up stored procedures to handle inserts, updates, and deletes with the data adapter. Stored procedures do not have to be interpreted, compiled or even transmitted from the client, and cut down on both network traffic and server overhead. Be sure to use CommandType.StoredProcedure instead of CommandType.Text&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Use StringBuilder for Complex String Manipulation&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;When a string is modified, the run time will create a new string and return it, leaving the original to be garbage collected. Most of the time this is a fast and simple way to do it, but when a string is being modified repeatedly it begins to be a burden on performance: all of those allocations eventually get expensive. &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Minimize the Use of Format()&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;When you can, use toString() instead of format(). In most cases, it will provide you with the functionality you need, with much less overhead.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Optimize Assignments&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Use exp += val instead of exp = exp + val. Since exp can be arbitrarily complex, this can result in lots of unnecessary work. This forces the JIT to evaluate both copies of exp, and many times this is not needed. The first statement can be optimized far better than the second, since the JIT can avoid evaluating the exp twice.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Keep Your Datasets Lean&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Only put the records you need into the dataset. Remember that the dataset stores all of its data in memory, and that the more data you request, the longer it will take to transmit across the wire.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Limit ASP.NET Server Controls&lt;/span&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;Exceptions and session state impose overhead. Surprise—so do ASP.NET server controls. They require server-side support, which leads to communication between your server and the client to support the control, and resource consumption on the server. Avoid the temptation to drop the server control onto your form and forget about it. In fact, you might be better off with a regular HTML control. Use the server control only if you plan to control the properties of a control programmatically, use view state to hold data values of the control, or handle server-side events generated by the control.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Use Page.IsPostBack&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;You need to take a series of steps when your page loads for the first time to perform setup formatting on the page or initialize data. However, you don't need to keep reinventing this wheel the next time a page is requested—and the next and the next. Avoid initializing the data again on the postback.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-8472282312513244132?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/8472282312513244132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=8472282312513244132' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8472282312513244132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/8472282312513244132'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/performance-tips-for-aspnet.html' title='Performance Tips for ASP.NET Applications'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-5980399864531457000</id><published>2008-06-13T13:45:00.024+05:30</published><updated>2008-06-25T11:53:54.065+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips / Tricks'/><title type='text'>.Net Tips and Tricks (Part -II)</title><content type='html'>&lt;strong&gt;&lt;span style="color:#990000;"&gt;How to form Color Picker in ASP.NET&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="font-size:78%;"&gt;[Click to enlarge]&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;click&gt;&lt;span style="font-size:85%;"&gt;&lt;a href="http://bp0.blogger.com/_gOWJOejMX_U/SFIw-TFbxYI/AAAAAAAAADo/Ltbh4mxGtG0/s1600-h/Code1.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5211281565654173058" style="CURSOR: hand" alt="" src="http://bp0.blogger.com/_gOWJOejMX_U/SFIw-TFbxYI/AAAAAAAAADo/Ltbh4mxGtG0/s400/Code1.JPG" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:100%;"&gt;Make sure to Import the System.Reflections namespace, as well as the System.Drawing namespace, for this example&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Prevent caching of webform in Asp.net&lt;/span&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;private void Page_Load(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;if(!Page.IsPostBack)&lt;br /&gt;{&lt;br /&gt;Response.Cache.SetCacheability(HttpCacheability.NoCache);&lt;br /&gt;Response.Cache.SetAllowResponseInBrowserHistory(false);&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;ASP.Net Server Controls Not Showing on pages&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Try running aspnet_regiis from the command prompt. Here's the default location: C:\WINNT\Microsoft.NET\Framework\&lt;&gt;\aspnet_regiis.exe -i&lt;/p&gt;&lt;p&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;Currently logged in user&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;To get the user ID of the user who is currently logged in, you would get it using this: System.Web.HttpContext.Current.User.Identity.Name&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Get windows Identity(win auth)&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Disabling a Button Until Processing is Complete&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Here's the scenario - let's say you have an Insert subroutine, called 'doInsert'. You want to immediately disable the Submit button, so that the end-user won't click it multiple times, therefore, submitting the same data multiple times.&lt;/p&gt;&lt;p&gt;For this, use a regular HTML button, including a Runat="server" and an 'OnServerClick' event designation - like this: &lt;/p&gt;&lt;p&gt;INPUT id="Button1" onclick="document.form1.Button1.disabled=true;" type="button" value="Submit - Insert Data" name="Button1" runat="server" onserverclick="doInsert" &lt;/p&gt;&lt;p&gt;Then, in the very last line of the 'doInsert' subroutine, add this line: Button1.enabled="True"&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Adding a MailTo Link inside a DataGrid&lt;/span&gt;&lt;/strong&gt; &lt;/p&gt;&lt;p&gt;Suppose you have a database table which contains an email field, and you'd like to display that field, as well as others in a DataGrid. Let's go one step further - - let's say you'd like to display that email field as a clickable MailTo link. One way that this can be easily be done using TemplateColumns. First, you create your DataGrid start and end tags. Then, inside these tags, you include 'Columns' start and end tags. That's where you put your TemplateColumn. Here's how to do it&lt;/p&gt;&lt;p&gt;&lt;a href="http://bp3.blogger.com/_gOWJOejMX_U/SFIzyHDfvdI/AAAAAAAAAD4/H0X6Q0cEOGA/s1600-h/Code2.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5211284654801272274" style="CURSOR: hand" alt="" src="http://bp3.blogger.com/_gOWJOejMX_U/SFIzyHDfvdI/AAAAAAAAAD4/H0X6Q0cEOGA/s400/Code2.JPG" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Use Path.GetRandomFileName() or Path.GetTempFileName() when working with temp files&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Do not reinvent function for generating unique name for temporary files. Use one of the existing methods:&lt;br /&gt;*** System.IO.Path.GetTempFileName() - use this method if you want to create temporary file in user's temp folder.&lt;br /&gt;*** System.IO.Path.GetRandomFileName() - use this method if you just want to generate unique file name. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Popup Window Code&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;You can use Javascript to do so. e.g. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000000;"&gt;input type="Button" Value="Open New" onclick="Javascript:window.open('webform1.aspx');"&lt;/p&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Uploading Large Size File&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;The default file size limit for the FileUpload control in ASP.Net is 4Mb. To get around this, in the HTTPRuntime section of the Web.config file, you can set the 'maxRequestLength' (in kb):&lt;br /&gt;&lt;/span&gt;[system.web]&lt;br /&gt;[httpRuntime maxRequestLength="1500000" /]&lt;br /&gt;[/system.web]&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;How to Register User Controls and Custom Controls in Web.config&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;ASP.NET 2.0 makes control declarations much cleaner and easier to manage. Instead of duplicating them on all your pages, just declare them once within the new pages-&gt;controls section with the web.config file of your application:&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_gOWJOejMX_U/SGHdDIyiS-I/AAAAAAAAAFE/AnXGK4jdBiA/s1600-h/Config.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5215692889440537570" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_gOWJOejMX_U/SGHdDIyiS-I/AAAAAAAAAFE/AnXGK4jdBiA/s400/Config.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Once you register the controls within the web.config file, you can then just use the controls on any page, master-page or user control on your site like so (no registration directives required):&lt;br /&gt;[html]&lt;br /&gt;[body]&lt;br /&gt;[form id="form1" runat="server]&lt;br /&gt;[scott:header ID="MyHeader" runat="server" /]&lt;br /&gt;[/form]&lt;br /&gt;[/body]&lt;br /&gt;[/html]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-5980399864531457000?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/5980399864531457000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=5980399864531457000' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5980399864531457000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/5980399864531457000'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/net-tips-and-tricks-part-ii.html' title='.Net Tips and Tricks (Part -II)'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_gOWJOejMX_U/SFIw-TFbxYI/AAAAAAAAADo/Ltbh4mxGtG0/s72-c/Code1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-4762629200535854902</id><published>2008-06-13T12:55:00.014+05:30</published><updated>2008-06-25T11:36:33.874+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips / Tricks'/><title type='text'>.Net Tips and Tricks (Part -I)</title><content type='html'>&lt;strong&gt;&lt;span style="color:#990000;"&gt;Use "App_Offline.htm" feature while updating a web site&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;"App_Offline.htm" feature provides a super convenient way to bring down an ASP.NET application while you updating a lot of content or making big changes to the site where you want to ensure that no users are accessing the application until all changes are done. The way app_offline.htm works is that you place this file in the root of the application. When ASP.NET sees it, it will shut-down the app-domain for the application and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;You have developed and deployed a web application on a web server. When users are making a request to the default.aspx file on the web server from their browser, they are being prompted to download the default.aspx file on their computer. What could be the problem.&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;Problem with aspnet_isapi.dll This behavior means that although the request is going to the IIS, it is not being executed by the asp.net worker process because IIS is not sure what to do with this file. This is because the aspnet_isapi.dll is either not present or IIS is not pointing to aspnet_isapi.dll.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Password matching regular expression&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit. ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Make Window Fit any Resolution&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_gOWJOejMX_U/SFIke9Rs_mI/AAAAAAAAADI/LfKJzE7EFcs/s1600-h/Script.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5211267833084575330" style="CURSOR: hand" alt="" src="http://bp3.blogger.com/_gOWJOejMX_U/SFIke9Rs_mI/AAAAAAAAADI/LfKJzE7EFcs/s320/Script.JPG" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Quickly move to matching brace in Visual Studio&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Just press Ctrl+] and VS.NET will take you to the matching brace. It also will take you to the matching comment, region or quote depending on what is at the cursor now.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Incremental search in Visual Studio.&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Press Ctrl+I.&lt;br /&gt;Start typing the text you are searching for. (Note: you'll see the cursor jump to the first match, highlighting the current search string.)&lt;br /&gt;Press Ctrl+I again to jump to the next occurrence of the search string.&lt;br /&gt;To stop search, press Esc.&lt;br /&gt;&lt;strong&gt;Advanced tip&lt;/strong&gt;: Press Ctrl+Shift+I to search backwards&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Clear all text boxes in ASP.Net&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;a href="http://bp0.blogger.com/_gOWJOejMX_U/SFIrpyKJbYI/AAAAAAAAADY/-Tud3jp6RHg/s1600-h/Code.JPG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5211275715660049794" style="WIDTH: 412px; CURSOR: hand; HEIGHT: 134px" height="124" alt="" src="http://bp0.blogger.com/_gOWJOejMX_U/SFIrpyKJbYI/AAAAAAAAADY/-Tud3jp6RHg/s400/Code.JPG" width="480" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;This will clear EVERYTHING from the textboxes - even if you had them pre-populated with data. A simple way to just reset it to the condition at Page_Load time, just do this in the Reset SubRoutine: Server.Transfer("YourPageName.aspx")&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;How to rotate a Label Text?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;[asp:Label id="Label1" style="writing-mode:tb-rl" runat="server"]Label[/asp:Label]&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Get Row Index with Gridview Select Button&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;When you autoGenerate a Select button with a Gridview, to find the RowIndex for that particular row, you can use the SelectedIndexChanged Event. Inside that event, try something like this (with a label called 'Label1':&lt;br /&gt;&lt;span style="color:#006600;"&gt;Dim row As GridViewRow = MyGridView.SelectedRow&lt;br /&gt;Dim intRow as Integer=Row.RowIndex&lt;br /&gt;label1.text=intRow.ToString&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#990000;"&gt;Auto select Gridview Row when Editing&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Let's say you have an editable Gridview, and you'd like to change the backcolor of the row you're editing, when you click the 'Edit' link for that row. It's very simple, and it's done in the Gridview's RowEditing Event.&lt;/p&gt;&lt;p&gt;First, you must set the SelectedIndex of the Gridview to the row you're editing:&lt;br /&gt;&lt;span style="color:#006600;"&gt;YourGridviewID.SelectedIndex = e.NewEditIndex&lt;/span&gt;&lt;/p&gt;&lt;p&gt;And, lastly, you must change the backcolor:&lt;br /&gt;&lt;span style="color:#006600;"&gt;YourGridviewID.SelectedRow.BackColor = Drawing.Color.Pink&lt;/span&gt;&lt;/p&gt;&lt;p&gt;You can, of course, accomplish any other row formatting options here, also.&lt;br /&gt;Full code and Subroutine is here:&lt;br /&gt;&lt;span style="color:#006600;"&gt;Protected Sub YourGridviewID_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles YourGridviewID.RowEditing &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#006600;"&gt;YourGridviewID.SelectedIndex = e.NewEditIndex&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#006600;"&gt;YourGridviewID.SelectedRow.BackColor = Drawing.Color.Pink&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#006600;"&gt;End Sub&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-4762629200535854902?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/4762629200535854902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=4762629200535854902' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/4762629200535854902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/4762629200535854902'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/net-tips-and-tricks.html' title='.Net Tips and Tricks (Part -I)'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_gOWJOejMX_U/SFIke9Rs_mI/AAAAAAAAADI/LfKJzE7EFcs/s72-c/Script.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-3417821048005412476</id><published>2008-06-13T11:29:00.015+05:30</published><updated>2008-06-13T11:55:10.781+05:30</updated><title type='text'>System.Configuration Namespace</title><content type='html'>The heart of the new .NET 2.0 configuration gem is the &lt;span style="color:#ff6600;"&gt;System.Configuration&lt;/span&gt; namespace. By default, this namespace is available when the System.dll assembly is referenced. It includes all of the configuration features of .NET 1.1, including the old &lt;span style="color:#ff6600;"&gt;ConfigurationSettings&lt;/span&gt; class (now deprecated in .NET 2.0). To gain access to all of the new .NET 2.0 configuration features, however, you must add a reference to the &lt;span style="color:#ff6600;"&gt;System.Configuration.dll&lt;/span&gt; assembly. It is in this assembly that you will find the core of the new configuration system, the &lt;span style="color:#ff6600;"&gt;ConfigurationManager&lt;/span&gt; static class.&lt;br /&gt;&lt;br /&gt;The &lt;span style="color:#ff6600;"&gt;ConfigurationManager&lt;/span&gt; class is a globally accessible doorway to an application's configuration. Since the class is static, all of its members are also static. This makes reading configuration such as AppSettings, ConnectionStrings and custom configuration sections a breeze. While this is similar to the ConfigurationSettings class, it also provides several new features that allow more secure access to an application's configuration. These new features also allow configuration settings to be saved to any configuration section: custom or otherwise.&lt;br /&gt;&lt;br /&gt;Beyond the &lt;span style="color:#ff6600;"&gt;ConfigurationManager&lt;/span&gt; class lies the life-blood of custom configuration sections. The following outlines the base classes available to help you write your own configuration object model. In addition to a set of base classes is a set of validators that can be used to ensure the accuracy of your custom configuration. Also, in the event that your needs are simple enough, a few pre-made configuration sections are available.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The base types&lt;/strong&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationSection&lt;/span&gt; - The base class of all configuration sections &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationSectionCollection&lt;/span&gt; - The base class of a collection of configuration sections &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationSectionGroup&lt;/span&gt; - The base class of a configuration section group &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationSectionGroupCollection&lt;/span&gt; - The base class of a collection of configuration section groups &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationElement&lt;/span&gt; - The base class of a configuration element &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationElementCollection&lt;/span&gt; - The base class of a collection of configuration elements &lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationConverterBase&lt;/span&gt; - The base class of a custom converter &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationValidatorBase&lt;/span&gt; - The base class of a custom validator &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;The support types&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationManager&lt;/span&gt; - Allows global access to all of an application's configuration &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;Configuration&lt;/span&gt; - A class that represents an application's configuration &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationProperty&lt;/span&gt; - A class that represents a single configuration property &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationPropertyAttribute&lt;/span&gt; - An attribute class that supports declarative definition of configuration &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationPropertyCollection&lt;/span&gt; - A collection of configuration properties &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConfigurationPropertyOptions&lt;/span&gt; - Enumeration of possible configuration property options &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;The validation types&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;CallbackValidator&lt;/span&gt; - Allows dynamic validation of a configuration value &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;CallbackValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying callback validators &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;IntegerValidator&lt;/span&gt; - Allows validation of an integer (Int32) configuration value &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;IntegerValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying integer validators &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;LongValidator&lt;/span&gt; - Allows validation of a long (Int64) configuration value &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;LongValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying long validators &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;PositiveTimeSpanValidator&lt;/span&gt; - Allows validation of a positive time span configuration value&lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;PositiveTimeSpanValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying positive time span validators &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;RegexStringValidator&lt;/span&gt; - Allows validation of a string configuration value with a regular expression &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;RegexStringValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying regex validators &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;StringValidator&lt;/span&gt; - Allows validation of a string configuration value &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;StringValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying string validators &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;SubclassTypeValidator&lt;/span&gt; - Allows validation that a configuration value derives from a given type &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;SubclassTypeValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying subclass type validators &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;TimeSpanValidator&lt;/span&gt; - Allows validation of a time span configuration value &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;TimeSpanValidatorAttribute&lt;/span&gt; - Attribute class for declaratively applying time span validators &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;The converter types&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;CommaDelimitedStringCollectionConverter&lt;/span&gt; - Converts a comma-delimited value to/from CommaDelimitedStringCollection &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;GenericEnumConverter&lt;/span&gt; - Converts between a string and an enumerated type &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;InfiniteIntConverter&lt;/span&gt; - Converts between a string and the standard infinite or integer value &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;InfiniteTimeSpanConverter&lt;/span&gt; - Converts between a string and the standard infinite TimeSpan value &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;TimeSpanMinutesConverter&lt;/span&gt; - Converts to and from a time span expressed in minutes &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;TimeSpanMinutesOrInfiniteConverter&lt;/span&gt; - Converts to and from a time span expressed in minutes or infinite &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;TimeSpanSecondsConverter&lt;/span&gt; - Converts to and from a time span expressed in seconds &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;TimeSpanSecondsOrInfiniteConverter&lt;/span&gt; - Converts to and from a time span expressed in seconds or infinite &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;TypeNameConverter&lt;/span&gt; - Converts between a Type object and the string representation of that type &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;WhiteSpaceTrimStringConverter&lt;/span&gt; - Converts a string to its canonical format, i.e. white space trimmed from front and back &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Pre-made configuration sections&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;AppSettingsSection&lt;/span&gt; - This provides the well-known &lt;appsettings&gt;configuration section &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ConnectionStringsSection&lt;/span&gt; - This provides the new &lt;connectionstrings&gt;configuration section &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;ProtectedConfigurationSection&lt;/span&gt; - This provides an encrypted configuration section &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;IgnoreSection&lt;/span&gt; - Special configuration section wrapper that is ignored by the configuration parser &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Premade configuration collections&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;CommaDelimitedStringCollection&lt;/span&gt; - Used in conjunction with &lt;span style="color:#990000;"&gt;CommaDelimitedStringCollectionConverter&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;KeyValueConfigurationCollection&lt;/span&gt; - Used to configure key/value pairs in your configuration sections &lt;/li&gt;&lt;li&gt;&lt;span style="color:#990000;"&gt;NameValueConfigurationCollection&lt;/span&gt; - Used to configure name/value pairs in your configuration sections &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In addition to all of the classes described above, you will also find other support types used by &lt;span style="color:#990000;"&gt;ProtectedConfigurationSection&lt;/span&gt;. All of the old .NET 1.x configuration classes will also still be available in the &lt;span style="color:#ff6600;"&gt;System.Configuration&lt;/span&gt; namespace, but for the most part they can be ignored.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-3417821048005412476?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/3417821048005412476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=3417821048005412476' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/3417821048005412476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/3417821048005412476'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/systemconfiguration-namespace.html' title='System.Configuration Namespace'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6011381329995167460.post-1487426117691016672</id><published>2008-06-12T15:46:00.017+05:30</published><updated>2009-05-02T21:23:10.868+05:30</updated><title type='text'>.Net knowledge base</title><content type='html'>&lt;span style="font-family:verdana;"&gt;The following links are very important inorder to brush up your .Net knowledge.&lt;/span&gt; &lt;ul&gt;&lt;li&gt;&lt;a href="http://www.aspnetfaq.com/"&gt;http://www.aspnetfaq.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharpfriends.com/Spec/index.aspx?specID=toc.htm"&gt;http://www.csharpfriends.com/Spec/index.aspx?specID=toc.htm&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.devbistro.com/tech-interview-questions/.NET.jsp"&gt;http://www.devbistro.com/tech-interview-questions/.NET.jsp&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.thinkinterview.com/Tags/ASP.NET-2.0-Interview-Questions-Tutorial.aspx"&gt;http://www.thinkinterview.com/Tags/ASP.NET-2.0-Interview-Questions-Tutorial.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.syncfusion.com/faq/aspnet/default.aspx"&gt;http://www.syncfusion.com/faq/aspnet/default.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://kyapoocha.com/"&gt;http://kyapoocha.com/&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://dotnetguts.blogspot.com/"&gt;http://dotnetguts.blogspot.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://aspnet35.blogspot.com/search/label/ASP.NET%20FAQs"&gt;http://aspnet35.blogspot.com/search/label/ASP.NET%20FAQs&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/asp.net/aa336670.aspx"&gt;http://msdn.microsoft.com/en-us/asp.net/aa336670.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://msvs2008.blogspot.com/"&gt;http://msvs2008.blogspot.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.dotnetquestion.info/dot_net/interview.htm"&gt;http://www.dotnetquestion.info/dot_net/interview.htm&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://prepareforjob.com/CommonHome.aspx?mid=1"&gt;http://prepareforjob.com/CommonHome.aspx?mid=1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.dotnetuncle.com/"&gt;http://www.dotnetuncle.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdotnetsupport.blogspot.com/"&gt;http://msdotnetsupport.blogspot.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.learnvisualstudio.net/"&gt;http://www.learnvisualstudio.net/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.techbaba.com/faqs/asp.net+question+answers.aspx"&gt;http://www.techbaba.com/faqs/asp.net+question+answers.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.vijaymukhi.com/"&gt;http://www.vijaymukhi.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.vijaymukhi.com/documents/books/aspnet1/contents.htm"&gt;http://www.vijaymukhi.com/documents/books/aspnet1/contents.htm&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://vikasnetdev.blogspot.com/2006/06/nice-interview-questions-found-in-job.html"&gt;http://vikasnetdev.blogspot.com/2006/06/nice-interview-questions-found-in-job.html&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blogs.crsw.com/mark/articles/254.aspx"&gt;http://blogs.crsw.com/mark/articles/254.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://dotnet-question-answer.blogspot.com/"&gt;http://dotnet-question-answer.blogspot.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.techinterviews.com/?p=176"&gt;http://www.techinterviews.com/?p=176&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.coolinterview.com/"&gt;http://www.coolinterview.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.c-sharpcorner.com/Interviews/"&gt;http://www.c-sharpcorner.com/Interviews/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://aspnetinfo.googlepages.com/home"&gt;http://aspnetinfo.googlepages.com/home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.techbaba.com/faqs/sql+server+question+answers.aspx"&gt;http://www.techbaba.com/faqs/sql+server+question+answers.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.megasolutions.net/kb/ASP_Net_InterView_Questions_1a.aspx"&gt;http://www.megasolutions.net/kb/ASP_Net_InterView_Questions_1a.aspx&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6011381329995167460-1487426117691016672?l=techiemate.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techiemate.blogspot.com/feeds/1487426117691016672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6011381329995167460&amp;postID=1487426117691016672' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/1487426117691016672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6011381329995167460/posts/default/1487426117691016672'/><link rel='alternate' type='text/html' href='http://techiemate.blogspot.com/2008/06/net-knowledge-base.html' title='.Net knowledge base'/><author><name>Techie Mate</name><uri>http://www.blogger.com/profile/05529718294081550882</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
