Posts

Custom error mode off in web config

Three error modes in which an ASP.NET application can work: 1) Off Mode 2) On Mode 3) RemoteOnly Mode The Error mode attribute determines whether or not an ASP.NET error message is displayed. By default, the mode value is set to "RemoteOnly". Off Mode When the error attribute is set to "Off", ASP.NET uses its default error page for both local and remote users in case of an error. <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <customErrors mode="Off" /> </system.web> </configuration> On Mode In case of "On" Mode, ASP.NET uses user-defined custom error page instead of its default error page for both local and remote users. If a custom error page is not specified, ASP.NET shows the error page describing how to enable remote viewing of errors. <? xml version =" 1.0" encoding =" utf-8" ? > < configuration ...

C# Tips that improve code efficiency and productivity

C# is a wonderful programming language; This tips that you can use to improve code efficiency, make your code more compact and achieve productivity. 1. Ternary Operator (?:) Ternary operator. The ternary operator tests a condition. It compares 2 values. It produces a third value that depends on the result of the comparison. The ternary effect can be accomplished with if-statements or other constructs. The ternary operator provides an elegant and equivalent syntax form to the if-statement. Example. One use of a ternary is to initialize a variable with the result of the expression. The C# compiler translates the ternary expression into branch statements such as brtrue. IL However: The high-level ternary statement is useful because it allows you to condense multiple if-statements and reduce nesting. Tip: It does not actually eliminate branching. It simplifies the high-level representation of the branching.   Based on: .NET 4.6 C# progra...

How to improve performance of code in c#

1. Knowing when to use StringBuilder You must have heard before that a StringBuilder object is much faster at appending strings together than normal string types. The thing is StringBuilder is faster mostly with big strings. This means if you have a loop that will add to a single string for many iterations then a StringBuilder class is definitely much faster than a string type. However if you just want to append something to a string a single time then a StringBuilder class is overkill. A simple string type variable in this case improves on resources use and readability of the C# source code. Simply choosing correctly between StringBuilder objects and string types you can optimize your code. 2. Comparing Non-Case-Sensitive Strings In an application sometimes it is necessary to compare two string variables, ignoring the cases. The tempting and traditionally approach is to convert both strings to all l...

Differnce between JavaScript jQuery and AJAX?

JavaScript  JavaScript is a client-side (in the browser) scripting language.  JavaScript lets you supercharge your HTML with animation, interactivity, and dynamic visual effects  JavaScript can make web pages more useful by supplying immediate feedback.  JavaScript is the common term for a combination of the ECMAScript programming language plus some means for accessing a web browser's windows and the document object model (DOM).  JavaScript was designed to add interactivity to HTML pages  Everyone can use JavaScript without purchasing a license  jQuery  jQuery is a library/framework built with JavaScript.  It abstracts away cross-browser compatibility issues and it emphasises unobtrusive and callback-driven JavaScript programming  jQuery (website) is a JavaScript framework that makes working with the DOM easier by building many high level functionality that can be used to search and interact with the DOM  jQuery imp...

ASP.NET page cycle

Each request for an .aspx page that hits IIS is handed over to the HTTP Pipeline. The HTTP Pipeline is a chain of managed objects that sequentially process the request and convert it to plain HTML text content. The starting point of a HTTP Pipeline is the HttpRuntime class. The ASP.NET infrastructure creates each instance of this class per AppDomain hosted within the worker process. The HttpRuntime class picks up an HttpApplication object from an internal pool and sets it to work on the request. It determines what class handles the request. The association between the resources and handlers are stored in the configurable file of the application. In web.config and also inmachine.config you will find these lines in section. If you run through the following program then it will be much easier to follow: <add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/> This extension can be associated with Han...

Difference between Abstract class and interface

Image
A class can implement any number of interfaces but a subclass can at most use only one abstract class. An abstract class can have non-abstract methods (concrete methods) whereas all methods of interfaces must be abstract. An abstract class can declare or use any variables whereas an interface is not allowed to do so. The following code compiles properly since no field declaration is in the interface. interface TestInterface {     int x = 4;  // Filed Declaration in Interface     void getMethod();     string getName(); }   abstract class TestAbstractClass {     int i = 4;     int k = 3;     public abstract void getClassName(); } It will generate a compile time error as: Error1 - Interfaces cannot contain fields. So we need to omit the Field Declaration to compile the code properly. interf...

Difference between a DataReader, a DataAdapter, a Dataset

Image
DataReader Connection Oriented architecture. DataReader is used to read data from database and it is a read and forward only connection  oriented architecture during fetching data from databaset. DataReader is used to iterate through result set that came from server and it will read one record at a time, that is why memory consumption will be less and it will fetch the data very fast when compared with DataSet. Generally we will use ExecuteReader object to bind data to DataReader. DataSet Disconnected architecture. This means there is no need of active connections whne we are work with datasets and it is a collection of datatables and relations among tables. It is used to hold multiple tables with data. You can select data from tables and views. Also DataSet provides you with rich features like saving data as XML and loading XML data. DataAdapter Disconnected architecture. DataAdapter will acts as a bridge between DataSet and database. This DataAdapter obj...