Skip to main content

Posts

Showing posts from October, 2015

Understanding Caching in Asp.Net MVC

ching is a most important aspect of high-performance web application. Caching provides a way of storing frequently accessed data and reusing that data. Practically, this is an effective way for improving web application’s performance. Advantage of Caching Reduce hosting server round-trips When content is cached at the client or in proxies, it cause minimum request to server. Reduce database server round-trips When content is cached at the web server, it can eliminate the database request. Reduce network traffic When content is cached at the client side, it it also reduce the network traffic. Avoid time-consumption for regenerating reusable content When reusable content is cached, it avoid the time consumption for regenerating reusable content. Improve performance Since cached content reduce round-trips, network traffic and avoid time consumption for regenerating reusable content which cause a boost in the performance. Key points about Caching Use cac

Implicitly Typed Local Variables in C#

Local variables can be given an inferred "type" of  var  instead of an explicit type. The  var  keyword instructs the compiler to infer the type of the variable from the expression on the right side of the initialization statement. The inferred type may be a built-in type, an anonymous type, a user-defined type, or a type defined in the .NET Framework class library.  The following examples show various ways in which local variables can be declared with  var : // i is compiled as an int var i = 5; // s is compiled as a string var s = "Hello" ; // a is compiled as int[] var a = new [] { 0, 1, 2 }; // expr is compiled as IEnumerable<Customer> // or perhaps IQueryable<Customer> var expr = from c in customers where c.City == "London" select c; // anon is compiled as an anonymous type var anon = new { Name = "Terry" , Age = 34 }; // list is compiled as List<int> var

Structs in C#

Like classes, structs are data structures that can contain data members and function members, but unlike classes, structs are value types and do not require heap allocation. A variable of a struct type directly stores the data of the struct, whereas a variable of a class type stores a reference to a dynamically allocated object. Struct types do not support user-specified inheritance, and all struct types implicitly inherit from type object . Structs are particularly useful for small data structures that have value semantics. Complex numbers, points in a coordinate system, or key-value pairs in a dictionary are all good examples of structs. The use of structs rather than classes for small data structures can make a large difference in the number of memory allocations an application performs. For example, the following program creates and initializes an array of 100 points. With Point implemented as a class, 101 separate objects are instantiated—one for the array and one each for

Events in C#

An event is a member that enables a class or object to provide notifications. An event is declared like a field except that the declaration includes an event keyword and the type must be a delegate type. Within a class that declares an event member, the event behaves just like a field of a delegate type (provided the event is not abstract and does not declare accessors). The field stores a reference to a delegate that represents the event handlers that have been added to the event. If no event handles are present, the field is null . The List<T> class declares a single event member called Changed , which indicates that a new item has been added to the list. The Changed event is raised by the OnChanged virtual method, which first checks whether the event is null (meaning that no handlers are present). The notion of raising an event is precisely equivalent to invoking the delegate represented by the event—thus, there are no special language constructs for raising even

Getting Started with SignalR and MVC 5

This post introduces you to real-time web application development with ASP.NET SignalR and ASP.NET MVC 5.  In this post you will learn the following SignalR development tasks: Adding the SignalR library to an MVC 5 application. Creating hub and OWIN startup classes to push content to clients. Using the SignalR jQuery library in a web page to send messages and display updates from the hub. Prerequisites:  Visual Studio 2013. If you do not have Visual Studio, see  ASP.NET Downloads  to get the free Visual Studio 2013 Express Development Tool. This section shows how to create an ASP.NET MVC 5 application, add the SignalR library, and create the chat application. In Visual Studio, create a C# ASP.NET application that targets .NET Framework 4.5, name it SignalRChat, and click OK. In the  New ASP.NET Project  dialog, and select  MVC , and click  Change Authentication . Select  No Authentication  in the  Change Authentication  dialog, and click  OK . Note