Posts

Difference between IEnumerator and IEnumerable

IEnumerator is an interfaces. An IEnumerator is a that can enumerate. It has 2 methods (MoveNext and Reset) and a property Current. To use IEnumerator is if you want a nonstandard way of enumerating (not iterating one-by-one) and want to define custom iteration. You create a new class implementing IEnumerator. Code Snippet:     public class MyCustomIterate:IEnumerator     {         public object Current         {             get { throw new NotImplementedException(); }         }         public bool MoveNext()         {             throw new NotImplementedException();         }         public void Reset()         {             throw new NotImplementedException();         }     } IEnumerable   is also an interfaces. An IEnumerable is that can be enumerated. It has just one method called GetEnumerator that returns an enumerator that iterates through a collection. When you implement enumerator logic in any of your collection class, you need to implement I

How Does <%: ... %> Differ From <%= ... %> in ASP.Net MVC

The <%= ... %> syntax has been available in ASP.NET since the platform was first invented. Just like the equivalent syntaxes in PHP, JSP, Classic ASP, and many other platforms, it’s a way to emit dynamic values into the HTML response. But this raises a question of security: if the dynamic value may originally have been supplied by a user, how can you be sure it doesn’t contain any unwanted HTML or malicious JavaScript? The standard way to avoid any such risk is to HTML-encode the value before emitting it, which converts any special characters (e.g., < ) to harmless HTML entities (e.g., &lt; ) that the browser knows to treat as plain text. <%= Html.Encode(ViewData["greeting"]) %> The tricky bit is remembering to write Html.Encode() all the time, especially considering that sometimes you must not encode certain values because they may contain HTML that you do want (e.g., from HTML helper methods like Html.ActionLink() , which already take care of encoding an

Specify port number in ASP.NET Development Server

Image
By default, the web server assigns random selected port for localhost. For example, if you have created a web site and you are going to test a page named TestPage.aspx, when you see the URL might be the following. http://localhost:4049/TestPage.aspx Following step are given below to assign a static port for the ASP.NET Development Server 1.      In   the Solution Explorer , right click the name of web site. 1.      In the   Properties   pane, you will find   Use dynamic ports = True , change   Use dynamic ports =False . This will enable editing of the   Port number   property. 2.      In the   Properties   pane, change a   Port number. Now, whenever you run web site with in   Visual Studio Developer , the   ASP.NET Development Server   will listen on the specified port.

Difference between Convert.ToString() and ToString() method

Convert.ToString() handles null values and not throws ObjectReferenceNullException whereas ToString() does not handles the null value and throws the null exception error message. If you don't want to get the null exception if your object is null then you have to use Convert.ToString () Method.

Web Services and WCF services

Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them. Features Web Service WCF Hosting It can be hosted in IIS It can be hosted in IIS, windows activation service, Self-hosting, Windows service Programming [WebService] attribute has to be added to the class [ServiceContraact] attribute has to be added to the class Model [WebMethod] attribute represents the method exposed to client [OperationContract] attribute represents the method exposed to client Operation One-way, Request- Response are the different operations supported in web service One-Way, Request-Response, Duplex are different type of operations supported in WCF XML System.Xml.serialization name space is used for se

Exploring our Lazy Class

We’ll dive in by writing an generic class that represents the delayed (and lazy) computation, Lazy<T>.  Actually it is just a class that will execute a piece of code once somebody asks for the a result. It will also need to cache this result, so that we can enforce that the code is at most executed once. It is pretty easy to represent this in C#: for the ‘piece of code’ that we need to execute, we can use a Func   delegate. We’ll also use generics, since this ‘piece of code’ can return any .NET type. public class Lazy<T> {     private Func<T> func;     private T result;     private bool hasValue;     public Lazy(Func<T> func)     {         this .func = func;         this .hasValue = false ;     }     public T Value     {         get         {             if (! this .hasValue)             {                 this .result = this .func();                 this .hasValue = true ;             }             return this .result;         }     } } Our new cl

Server Variables in .Net Web Application

Server Variables Variable Description ALL_HTTP Returns all HTTP headers sent by the client. Always prefixed with HTTP_ and capitalized ALL_RAW Returns all headers in raw form APPL_MD_PATH Returns the meta base path for the application for the ISAPI DLL APPL_PHYSICAL_PATH Returns the physical path corresponding to the meta base path AUTH_PASSWORD Returns the value entered in the client's authentication dialog AUTH_TYPE The authentication method that the server uses to validate users AUTH_USER Returns the raw authenticated user name CERT_COOKIE Returns the unique ID for client certificate as a string CERT_FLAGS bit0 is set to 1 if the client certificate is present and bit1 is set to 1 if the cCertification authority of the client certificate is not valid CERT_ISSUER Returns the issuer field of the client certificate CERT_KEYSIZE Returns the number of bits in Secure Sockets Layer connection key size CERT_SECRETKEYSIZE Returns the number of bits in server certificate priv