Tips to Improve the Performance of an ASP.Net Application

1. Viewstate

This option looks like an extra feature for the end users. This needs to be loaded from the server and it adds more size to the page but it will affect the performance when we have many controls in the page, like user registration. So, if there is no need for it then it can be disabled.

EnableViewState = "false" needs to be given based on the requirements. It can be given at the control, page and config level settings.


2. Avoid Session and Application Variables

A Session is a storage mechanism that helps developers to take values across the pages. It will be stored based on the session state chosen. By default it will be stored in the Inproc. That default settings uses IIS. When this Session variable is used in a page that is accessed by many numbers then it will occupy more memory allocation and gives additional overhead to the IIS. It will make the performance slow.

It can be avoided for most scenarios . If you want to send the information across pages then we can use a Cross Post-back, Query string with encryption. If you want to store the information within the page then caching the object is the best way.


3. Use Caching

ASP.Net has the very significant feature of a caching mechanism. It gives more performance and avoids the client/server process. There are three types of caching in ASP.Net.

If there is any static content in the full pages then it should be used with the Output cache. What it does is, it stores the content on IIS. When the page is requested it will be loaded immediately from the IIS for the certain period of time. Similarly Fragment paging can be used to store the part of the web page.


4. Effectively use CSS and Script files

If you have large CSS files that are used for the entire site in multiple pages, then based on the requirements, it can be split and stored with different names. It will minimize the loading time of the pages.


5. Images sizes

Overuse of images in the web site affect the web page performance. It takes time to load the images, especially on dial-up connections. Instead of using the background images, it can be done on the CSS colors or use light-weight images to be repeated in all of the pages.


6. CSS based layout

The entire web page design is controlled by the CSS using the div tags instead of table layout. It increases the page loading performance dramatically. It will help to enforce the same standard guideline throughout the website. It will reduce the future changes easily. When we use the nested table layout it takes more time for rendering.


7. Avoid Round trips

We can avoid unnecessary database hits to load the unchanged content in the database. We should use the IsPostBack method to avoid round trips to the database.



8. Validate using JavaScript

Manual validation can be done at the client browser instead of doing at the server side. JavaScript helps us to do the validation at the client side. This will reduce the additional overhead to the server.
The plug-in software helps to disable the coding in the client browser. So, the sensitive application should do the server side validation before going into the process.


9. Clear the Garbage Collection

Normally .Net applications use Garbage Collection to clean the unused resources from memory. But it takes time to clear the unused objects from memory.

There are many ways to clean the unused resources. But not all of the methods are recommended. But we can use the dispose method in the finally block to clean up the resources. Moreover we need to close the connection. It will immediately free the resources and provides space in memory.


10. Avoid bulk data store on client side

Try to avoid more data on the client side. It will affect the web page loading. When we store more data on the hidden control then it will be encrypted and stored on the client side. It can be tampered with by hackers as well.


11. Implement Dynamic Paging

When we load a large number of records into the server data controls like GridView, DataList and ListView it will take time to load. So we can show only the current page data through the dynamic paging.


12. Use Stored Procedure

Try to use Stored Procedures. They will increase the performance of the web pages. Because it is stored as a complied object in the database and it uses the query execution plans. If you pass the query then it will make a network query.


13. Use XML and XSLT

XML and XSLT will speed up the page performance. If the process is not more complex then it can be implemented in XSLT.


14. Use Dataset

A DataSet is not lightweight compared with DataReader. But it has the advantages of a disconnected architecture. A DataSet will consume a substantial amount of memory. Even though it can have more than one day. If you want to perform many operations while loading the page itself, then it might be better to go with a DataSet. Once data is loaded into the DataSet it can be used later also.


15. Use String Builder in place of String

When we append the strings like mail formatting in the server side then we can use StringBuilder. If you use string for concatenation, what it does every time is it creates the new storage location for storing that string. It occupies more spaces in memory. But if we use the StringBuilder class in C# then it consumes more memory space than String.


16. Use Threads

Threads are an important mechanism in programming to utilize the system resources effectively. When we want to do a background process then it can be called a background process.


17. Use Server.Transfer

If you want to transfer the page within the current server then we can use the Server.Transfer method. It avoids roundtrips between the browser and server. But it won't update the browser history.

Consider the example of when clicked on send, it should send the mail to 5 lakhs members yet there is no need to wait for all the processes to complete. Just call the mail sending process as a background thread then proceed to do the further processing, because the sending of the mail is not dependent on any of the other processes.

SQL Constraints

SQL constraints are used to specify rules for the data in a table.

Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the table. If there is any violation between the constraint and the data action, the action is aborted.

Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table.


The following constraints are commonly used in SQL:

NOT NULL - Ensures that a column cannot have a NULL value

UNIQUE - Ensures that all values in a column are different

PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table

FOREIGN KEY - Prevents actions that would destroy links between tables

CHECK - Ensures that the values in a column satisfies a specific condition

DEFAULT - Sets a default value for a column if no value is specified

CREATE INDEX - Used to create and retrieve data from the database very quickly

Multiple Models in Single View in MVC

1. Using Dynamic Model

ExpandoObject (the System.Dynamic namespace) is a class that was added to the .Net Framework 4.0 that allows us to dynamically add and remove properties onto an object at runtime. Using this ExpandoObject, we can create a new object and can add our list of teachers and students into it as a property. We can pass this dynamically created object to the view and render list of the teacher and student.

Example

Controller Code

public class HomeController : Controller  

{  

    public ActionResult Index()  

    {  

        ViewBag.Message = "Welcome to my demo!";  

        dynamic mymodel = new ExpandoObject();  

        mymodel.Teachers = GetTeachers();  

        mymodel.Students = GetStudents();  

        return View(mymodel);  

    }  

}  

We can define our model as dynamic (not a strongly typed model) using the @model dynamic keyword.


View Code : 

@using MultipleModelInOneView;  

@model dynamic  

@{  

    ViewBag.Title = "Home Page";  

}  

<h2>@ViewBag.Message</h2>  

   

<p><b>Teacher List</b></p>  

   

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

    </tr>  

    @foreach (Teacher teacher in Model.Teachers)  

    {  

        <tr>  

            <td>@teacher.TeacherId</td>  

            <td>@teacher.Code</td>  

            <td>@teacher.Name</td>  

        </tr>  

    }  

</table>  

   

<p><b>Student List</b></p>  

   

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

        <th>Enrollment No</th>  

    </tr>  

    @foreach (Student student in Model.Students)  

    {  

        <tr>  

            <td>@student.StudentId</td>  

            <td>@student.Code</td>  

            <td>@student.Name</td>  

            <td>@student.EnrollmentNo</td>  

        </tr>  

    }  

</table>  



2. Using View Model


ViewModel is nothing but a single class that may have multiple models. It contains multiple models as a property. It should not contain any method.


In the above example, we have the required View model with two properties. This ViewModel is passed to the view as a model. To get intellisense in the view, we need to define a strongly typed view.


public class ViewModel  

{  

    public IEnumerable<Teacher> Teachers { get; set; }  

    public IEnumerable<Student> Students { get; set; }  

}  


Controller code

public ActionResult IndexViewModel()  

{  

    ViewBag.Message = "Welcome to my demo!";  

    ViewModel mymodel = new ViewModel();  

    mymodel.Teachers = GetTeachers();  

    mymodel.Students = GetStudents();  

    return View(mymodel);  

}  


View code

@using MultipleModelInOneView;  

@model ViewModel   

@{  

    ViewBag.Title = "Home Page";  

}  

<h2>@ViewBag.Message</h2>  

<p><b>Teacher List</b></p>  

   

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

    </tr>  

    @foreach (Teacher teacher in Model.Teachers)  

    {  

        <tr>  

            <td>@teacher.TeacherId</td>  

            <td>@teacher.Code</td>  

            <td>@teacher.Name</td>  

        </tr>  

    }  

</table>  

<p><b>Student List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

        <th>Enrollment No</th>  

    </tr>  

    @foreach (Student student in Model.Students)  

    {  

        <tr>  

            <td>@student.StudentId</td>  

            <td>@student.Code</td>  

            <td>@student.Name</td>  

            <td>@student.EnrollmentNo</td>  

        </tr>  

    }  

</table>  



3. Using ViewData


ViewData is used to transfer data from the controller to the view. ViewData is a dictionary object that may be accessible using a string as the key. Using ViewData, we can pass any object from the controller to the view. The Type Conversion code is required when enumerating in the view.

 

For the preceding example, we need to create ViewData to pass a list of teachers and students from the controller to the view.


Controller Code

public ActionResult IndexViewData()  

{  

    ViewBag.Message = "Welcome to my demo!";  

    ViewData["Teachers"] = GetTeachers();  

    ViewData["Students"] = GetStudents();  

    return View();  

}  


View Code

@using MultipleModelInOneView;  

@{  

    ViewBag.Title = "Home Page";  

}  

<h2>@ViewBag.Message</h2>  

 <p><b>Teacher List</b></p>   

@{  

  

   IEnumerable<Teacher> teachers = ViewData["Teachers"] as IEnumerable<Teacher>;  

   IEnumerable<Student> students = ViewData["Students"] as IEnumerable<Student>;  

}  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

    </tr>  

    @foreach (Teacher teacher in teachers)  

    {  

        <tr>  

            <td>@teacher.TeacherId</td>  

            <td>@teacher.Code</td>  

            <td>@teacher.Name</td>  

        </tr>  

    }  

</table>  

 <p><b>Student List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

        <th>Enrollment No</th>  

    </tr>  

    @foreach (Student student in students)  

    {  

        <tr>  

            <td>@student.StudentId</td>  

            <td>@student.Code</td>  

            <td>@student.Name</td>  

            <td>@student.EnrollmentNo</td>  

        </tr>  

    }  

</table>  



4. Using ViewBag


ViewBag is similar to ViewData and is also used to transfer data from the controller to the view. ViewBag is a dynamic property. ViewBag is just a wrapper around the ViewData.


Controller Code 

public ActionResult IndexViewBag()  

{  

    ViewBag.Message = "Welcome to my demo!";  

    ViewBag.Teachers = GetTeachers();  

    ViewBag.Students = GetStudents();  

    return View();  

}  


View Code

@using MultipleModelInOneView;  

@{  

    ViewBag.Title = "Home Page";  

}  

<h2>@ViewBag.Message</h2>  

<p><b>Teacher List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

    </tr>  

    @foreach (Teacher teacher in ViewBag.Teachers)  

    {  

        <tr>  

            <td>@teacher.TeacherId</td>  

            <td>@teacher.Code</td>  

            <td>@teacher.Name</td>  

        </tr>  

    }  

</table>  

<p><b>Student List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

        <th>Enrollment No</th>  

    </tr>  

    @foreach (Student student in ViewBag.Students)  

    {  

        <tr>  

            <td>@student.StudentId</td>  

            <td>@student.Code</td>  

            <td>@student.Name</td>  

            <td>@student.EnrollmentNo</td>  

        </tr>  

    }  

</table>  



5. Using Tuple


A Tuple object is an immutable, fixed-size and ordered sequence object. It is a data structure that has a specific number and sequence of elements. The .NET framework supports tuples up to seven elements.


Using this tuple object we can pass multiple models from the controller to the view.


Controller Code

public ActionResult IndexTuple()  

{  

    ViewBag.Message = "Welcome to my demo!";  

    var tupleModel = new Tuple<List<Teacher>, List<Student>>(GetTeachers(), GetStudents());  

    return View(tupleModel);  

}  


View Code

@using MultipleModelInOneView;  

@model Tuple <List<Teacher>, List <Student>>  

@{  

    ViewBag.Title = "Home Page";  

}  

<h2>@ViewBag.Message</h2>   

<p><b>Teacher List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

    </tr>  

    @foreach (Teacher teacher in Model.Item1)  

    {  

        <tr>  

            <td>@teacher.TeacherId</td>  

            <td>@teacher.Code</td>  

            <td>@teacher.Name</td>  

        </tr>  

    }  

</table>  

<p><b>Student List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

        <th>Enrollment No</th>  

    </tr>  

    @foreach (Student student in Model.Item2)  

    {  

        <tr>  

            <td>@student.StudentId</td>  

            <td>@student.Code</td>  

            <td>@student.Name</td>  

            <td>@student.EnrollmentNo</td>  

        </tr>  

    }  

</table>  


6. Using Render Action Method


A Partial View defines or renders a partial view within a view. We can render some part of a view by calling a controller action method using the Html.RenderAction method. The RenderAction method is very useful when we want to display data in the partial view. The disadvantages of this method is that there are only multiple calls of the controller.


In the following example, I have created a view (named partialView.cshtml) and within this view I called the html.RenderAction method to render the teacher and student list.


Controller Code


public ActionResult PartialView()  

{  

    ViewBag.Message = "Welcome to my demo!";  

    return View();  

}  

   

/// <summary>  

/// Render Teacher List  

/// </summary>  

/// <returns></returns>  

public PartialViewResult RenderTeacher()  

{  

    return PartialView(GetTeachers());  

}  

   

/// <summary>  

/// Render Student List  

/// </summary>  

/// <returns></returns>  

public PartialViewResult RenderStudent()  

{  

    return PartialView(GetStudents());  

}  

View Code


@{  

   ViewBag.Title = "PartialView";  

<h2>@ViewBag.Message</h2>  

<div>  

    @{  

        Html.RenderAction("RenderTeacher");  

        Html.RenderAction("RenderStudent");  

    }  

</div>  


RenderTeacher.cshtml

@using MultipleModelInOneView;  

@model IEnumerable<MultipleModelInOneView.Teacher>  

 <p><b>Teacher List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

    </tr>  

    @foreach (Teacher teacher in Model)  

    {  

        <tr>  

            <td>@teacher.TeacherId</td>  

            <td>@teacher.Code</td>  

            <td>@teacher.Name</td>  

        </tr>  

    }  

</table>  


RenderStudent.cshtml


@using MultipleModelInOneView;  

@model IEnumerable<MultipleModelInOneView.Student>   

<p><b>Student List</b></p>  

<table>  

    <tr>  

        <th>Id</th>  

        <th>Code</th>  

        <th>Name</th>  

        <th>Enrollment No</th>  

    </tr>  

    @foreach (Student student in Model)  

    {  

        <tr>  

            <td>@student.StudentId</td>  

            <td>@student.Code</td>  

            <td>@student.Name</td>  

            <td>@student.EnrollmentNo</td>  

        </tr>  

    }  

</table>  

Types of Routing in MVC

There are 2 types of Routing in MVC application

1. Conventional or Traditional Routing (Using Routing Config)

2. Attribute Routing (Available in MVC 5) 


1. Conventional or Traditional Routing

Conventional or Traditional Routing also is a pattern matching system for URL that maps incoming request to the particular controller and action method.

We set all the routes in the RouteConfig file.

RouteConfig file is available in the App_Start folder.

We need to register all the routes to make them operational.

RouteConfig file
public class RouteConfig  
{  
       public static void RegisterRoutes(RouteCollection routes)  
       {  
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
  
            routes.MapRoute(  
                name: "Default",  
                url: "{controller}/{action}/{id}",  
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }  
            );  
       }  
}  

Register RouteConfig in Global.asax
protected void Application_Start()  
{  
      AreaRegistration.RegisterAllAreas();   
      RouteConfig.RegisterRoutes(RouteTable.Routes);   
}  



2. Attribute Routing

It is a very simple routing method compared to conventional routing. All the concepts are just like the conventional approach but here, we define all the routes and attributes. In attribute, we define the routing on a simple controller or action method.  
 
For simply registering the attribute routing in our application, we need to add the following line in routeconfig.cs.
routes.MapMvcAttributeRoutes();  


Enabling Attribute Routing
To enable Attribute Routing, we need to call the MapMvcAttributeRoutes method of the route collection class during configuration.
public class RouteConfig  
{  
    public static void RegisterRoutes(RouteCollection routes)  
    {  
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
        routes.MapMvcAttributeRoutes();  
    } 
}

Attribute Routing Example
A route attribute is defined on top of an action method. The following is the example of a Route Attribute in which routing is defined where the action method is defined.
In the following example, I am defining the route attribute on top of the action method

public class HomeController : Controller  
{  
    //URL: /Mvctest  
    [Route(“Mvctest”)]  
    public ActionResult Index()  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
}}

Attribute Routing with Optional Parameter
We can also define an optional parameter in the URL pattern by defining a question mark (“?") to the route parameter. We can also define the default value by using parameter=value.

public class HomeController : Controller  
{  
  
  // Optional URI Parameter  
  // URL: /Mvctest/  
  // URL: /Mvctest/0023654  
  
    [Route(“Mvctest /{ customerName ?}”)]  
    public ActionResult OtherTest(string customerName)  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }  
  
   // Optional URI Parameter with default value  
  // URL: /Mvctest/  
  // URL: /Mvctest/0023654  
  
   [Route(“Mvctest /{ customerName =0036952}”)]  
   public ActionResult OtherTest(string customerName)  
    {  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }  


Route Prefixes
We can also set a common prefix for the entire controller (all action methods within the controller) using the “RoutePrefix” attribute.

[RoutePrefix(“Mvctest”)]  
public class HomeController : Controller  
{  
    // URL: /Mvctest/  
    [Route]  
    public ActionResult Index()  
    {  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }  
  
  // Optional URI Parameter  
  // URL: /Mvctest/  
  // URL: /Mvctest/0023654  
    [Route(“{ customerName }”)]  
    public ActionResult OtherTest(string customerName)  
    {  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }  

Defining Default Route using Route Attribute
We can also define a Route attribute on top of the controller, to capture the default action method as the parameter.

[RoutePrefix(“Mvctest”)]  
[Route(“action=index”)]  
public class HomeController : Controller  
{  
    // URL: /Mvctest/  
    public ActionResult Index()  
    {  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }   
  
    // URL: /Mvctest/NewMethod  
    public ActionResult NewMethod()  
    {  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }  

Defining Route name
We can also define a name of the route to allow easy URI generation.

[Route(“Mvctest”,  Name = "myTestURL")]  
public ActionResult Index()  
{  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
We can generate URI using Url.RouteUrl method.

<a href="@Url.RouteUrl("mainmenu")">Test URI</a>  
Defining Area

We can define the "Area" name from the controller that belongs to the using RouteArea attribute. If we define the “RouteArea” attribute on top of the controller, we can remove the AreaRegistration class from global.asax.
[RouteArea(“Test”)]  
[RoutePrefix(“Mvctest”)]  
[Route(“action=index”)]  
  
public class HomeController : Controller  
{  
    // URL: /Test/Mvctest/  
    public ActionResult Index()  
    {  
        ViewBag.Message = "Welcome to ASP.NET MVC!";  
        return View();  
    }  

Reactjs vs React Native

ReactJS is an open-source JavaScript library used to build the user interface for Web Applications. It is responsible only for the view layer of the application. It provides developers to compose complex UIs from a small and isolated piece of code called "components." ReactJS made of two parts first is components, that are the pieces that contain HTML code and what you want to see in the user interface, and the second one is HTML document where all your components will be rendered.

React Native is an open-source JavaScript framework used for developing a mobile application for iOS Android, and Windows. It uses only JavaScript to build a cross-platform mobile app. React Native is same as React, but it uses native components instead of using web components as building blocks. It targets mobile platforms rather than the browser. In March 2015, Facebook announced that React Native is open and available on GitHub.


Advantages of React Native

Cross-Platform Usage: It provides the facility of "Learn once write everywhere." It works for both platform Android as well as iOS devices.

Class Performance: The code written in React Native are compiled into native code, which enables it for both operating systems as well as it functions in the same way on both the platforms.

JavaScript: JavaScript knowledge is used to build native mobile apps.

Community: The large community of ReactJS and React Native helps us to find any answer we require.

Hot Reloading: Making a few changes in the code of your app will be immediately visible during development. If the business logic is changed, its reflection is live reloaded on screen.

Improving with Time: Some features of iOS and Android are still not supported, and the community is always inventing the best practices.

Native Components: We will need to write some platform specific code if we want to create native functionality, which is not designed yet.

Existence is Uncertain: As Facebook develop this framework, its presence is uncertain since it keeps all the rights to kill off the project anytime. As the popularity of React Native rises, it is unlikely to happen.


Disadvantage of React Native

React Native is Still New and Immature: React Native is a newbie in Android and iOS programming languages and is still in its improvement stage, which can have a negative impact on the apps.

Learning is Tough: React Native is not easy to learn, especially for a fresher in the app development field.

It Lacks the Security Robustness: React Native is a JavaScript library and open-source framework, which creates a gap in the security robustness. When you are creating banking and financial apps where data is highly confidential, experts advice not to choose React Native.

It Takes More Time to Initialize: React Native takes a lot of time for initializing the runtime even for the hi-tech gadgets and devices.




ReactJSReact Native
1The ReactJS initial release was in 2013.The React Native initial release was in 2015.
2It is used for developing web applications.It is used for developing mobile applications.
3It can be executed on all platforms.It is not platform independent. It takes more effort to be executed on all platforms.
4It uses a JavaScript library and CSS for animations.It comes with built-in animation libraries.
5It uses React-router for navigating web pages.It has built-in Navigator library for navigating mobile applications.
6It uses HTML tags.It does not use HTML tags.
7It can use code components, which saves a lot of valuable time.It can reuse React Native UI components & modules which allow hybrid apps to render natively.
8It provides high security.It provides low security in comparison to ReactJS.
9In this, the Virtual DOM renders the browser code.In this, Native uses its API to render code for mobile applications.



Difference Between =, == and === in JavaScript

What is = in JavaScript?

Equal to (=) is an assignment operator which sets the variable on the left of the = to the value of the expression that is on its right. This operator assigns lvalue to rvalue.


Why use = in JavaScript?

The = JavaScript operator assigns a value to the left operand depends on the value of operand available on the right side. The first operand should be a variable. ++The basic assignment operator is = that assigns the value of one operand to another. That is a = b assigns the value of b to a.

-------------------------

What is == in JavaScript?

Double equals (==) is a comparison operator which transforms the operands having the same type before comparison. So when you compare string with a number, JavaScript converts any string to a number. An empty string is always converts to zero. A string with no numeric value is converts to NaN (Not a Number) which returns false.


Why use == in JavaScript?

The == operator is an equality operator. It checks whether its two operands are the same or not by changing expression from one data type to others. You can use == operator in order to compare the identity of two operands even though they are not of a similar type.

-------------------------

What is === in JavaScript?

=== (Triple equals) is a strict equality comparison operator in JavaScript which returns false for the values which are not of a similar type. This operator performs type casting for equality. If we compare 2 with "2" using === then it will return a false value.


Why use === in JavaScript?

Strict equality === checks that two values are the same or not.

Value are not implicitly converted to some other value before comparison.

If the variable values are of different types, then the values are considered as unequal.

If the variable are of the same type are not numeric and have the same value they are considered as equal.

Lastly, If both variable values are numbers, they are considered equal if both are not NaN (Not a Number) and are the same value.

Eager Loading vs Lazy Loading vs Explicit Loading

Eager Loading

With Eager Loading, all the data is retrieved in a single query, which can then be cached to improve the Application performance. With Eager Loading, we are trading memory consumption for the database round trips.


Lazy Loading

With Lazy Loading, we only retrieve just the amount of data, which we need in a single query. When we need more data related to the initial data, additional queries are issued to the database. This means there are several round trips between the Application Server and the database Server. In general, these database round trips are very often the major performance bottleneck in most Applications. Lesser the round trips, better will be the performance.


Explicit Loading

Explicit loading is similar to lazy loading, except that: you explicitly retrieve the related data in code; it doesn’t happen automatically when you access a navigation property. in other words, Related entities are only loaded when you say “Load!”. The Explicit Loading is typically more efficient when you need the related data for all retrieved rows of the primary table. Explicit Loading would be a good practice to reduce further SQL queries.


Use of FortiClient

FortiClient is a client-based software solution that offers a range of security features for desktops and laptops. It is used in connection with FortiGate appliances, FortiClient delivers IPsec and SSL encryption, WAN optimization, endpoint compliance and two-factor authentication. A VPN(Virtual Private Network) client makes it easier for users to connect to a virtual private network.

FortiClient can be used as a VPN Client (IPSec and SSL), an AV client (it does ok in security benchmarks) and a host vulnerability scanners.

How To Connect to the FortiClient VPN :- 

Click Remote Access on the left side of the Forticlient. Select CAIU from the VPN Name drop down. Enter your IU username and password and click Connect. 

For FortiGate administrators, a free version of FortiClient VPN is available which supports basic IPsec and SSL VPN and does not require registration with EMS.

FortiClient is free if you do not want to manage the settings with a firewall and supports several operating systems. In addition to anti virus and VPN and vulnerability scanning it also acts as a web filter and can support more features.

How does Fortinet VPN Work ?

A VPN works by routing a device's internet connection through a private service rather than the user's regular internet service provider (ISP). Using a VPN creates a private, encrypted tunnel through which a user's device can access the internet while hiding their personal information, location, and other data.

Why I Cannot connect to FortiClient VPN ?

It might be a SSL/TLS issue. Try changing the TLS settings under Internet Properties -> Advanced Settings.

Why FortiClient VPN disconnects frequently?

Your Forticlient SSL VPN users might experience frequent disconnects, even if “Always On” check box is checked in Forticlient's login window. Note: timeout is in seconds , so 259200 seconds is 72 hours. You might want to decrease it as you see fit. ... This prevents users from just leaving VPN on overnight.

SQL Server Profiler

Microsoft SQL Server Profiler is a graphical user interface to SQL Trace for monitoring an instance of the Database Engine or Analysis Services. An SQL server profiler is a tool for tracing, recreating, and troubleshooting problems in MS SQL Server, Microsoft’s Relational Database Management System (RDBMS). We can save and reuse the state at a later point of time. It’s like a dashboard that shows the health of an instance of MS SQL Server. 

Users create traces to capture data and monitor errors and other problems. They then use the profiler to store, retrieve, and view the results of many traces graphically for purposes of troubleshooting and repair. This function all happens on the client-side, meaning it uses resources on the same machine it’s monitoring.

We can do the following using SQL Server Profiler

- Create a trace

- Watch the trace results as the trace runs

- Store the trace results in a table

- Start, stop, pause, and modify the trace results as necessary

- Replay the trace results


Event

An event is an action generated within an instance of SQL Server Database Engine. Examples of these are:

- Transact-SQL SELECT, INSERT, UPDATE, and DELETE statements.

- User login and logout

- Execution of Stored procedures

- Operation with cursor


Event Class

Event class is a type of event that can be traced. Some examples are:

- SQL: BatchCompleted

- SQL: Batch Starting

- Audit Login

- Audit Logout

- Lock: Acquired

- Lock: Released


Reply in SQL Server Profiler

SQL Server profiler has a Reply facility which has the ability to save a trace and replay it later.

Replay is useful to troubleshoot an application. Trace replay supports debugging by using Toggle Breakpoint and the Run to Cursor options on the SQL Server Profiler Replay menu.

Anything changed in SQL Server Management Studio will be traced by the SQL Profiler. So it can basically be used for database performance check. We also have "SQL Server Performance Monitor" to monitor the System and Server performance too.

Bundling and Minification

Bundling and minification techniques were introduced in MVC 4 to improve request load time. 

Bundling 

Bundling allows us to load the bunch of static files from the server in a single HTTP request.

The following figure illustrates the bundling technique(Loading script files in separate requests)

In the above figure, the browser sends two separate requests to load two different JavaScript file MyJavaScriptFile-1.js and MyJavaScriptFile-2.js.

The bundling technique in ASP.NET MVC allows us to load more than one JavaScript file, MyJavaScriptFile-1.js and MyJavaScriptFile-2.js in one request, as shown below.


Bundle Types
MVC 5 includes following bundle classes in System.web.Optimization namespace:
=> ScriptBundle: ScriptBundle is responsible for JavaScript minification of single or multiple script files.
=> StyleBundle: StyleBundle is responsible for CSS minification of single or multiple style sheet files.
=> DynamicFolderBundle: Represents a Bundle object that ASP.NET creates from a folder that contains files of the same type.

Minification

Minification technique optimizes script or CSS file size by removing unnecessary white space and comments and shortening variable names to one character.

For example, consider the following JavaScript function.
sayHello = function(name){
    var msg = "Hello" + name;
    alert(msg);
}

Minification will remove the unnecessary white spaces, comments, and shortening variable names to reduce the characters, which will reduce the size of the JavaScript file. The above JavaScript will be minimized as the following script.

sayHello=function(n){var t="Hello"+n;alert(t)}

SCHEMA in SQL Server

What is a Schema in SQL Server ?

A Schema in SQL is a collection of database objects associated with a database. The username of a database is called a Schema owner. Schema always belong to a single database whereas a database can have single or multiple schemas. Also, it is also very similar to separate namespaces or containers, which stores database objects. It includes various database objects including your tables,  views, procedures, index, etc. A SQL database contains multiple objects such as tables, views, stored procedures, functions, indexes, triggers. We define SQL Schema as a logical collection of database objects. A user owns that owns the schema is known as schema owner. It is a useful mechanism to segregate database objects for different applications, access rights, managing security administration of databases. We do not have any restrictions on the number of objects in a schema. We define default SQL Schema for a database user in the create database user window. If we do not define any default schema for a user, SQL Server assumes dbo as the default schema. 

We can verify the default schema for a user using the following system function:

SELECT SCHEMA_NAME();


We can query sys.schemas system table to find out schema in a database and their owners:

SELECT s.name AS schema_name, 

       s.schema_id, 

       u.name AS schema_owner

FROM sys.schemas s

     INNER JOIN sys.sysusers u ON u.uid = s.principal_id

ORDER BY s.name;


Starting from SQL Server 2005, we have different meanings of user and schema. Now, database objects owner is a schema and we define schema owners. We can have a single or multiple schema owners. 

Advantages of using Schema - 
You can apply security permissions for separating and protecting database objects based on user access rights.
A logical group of database objects can be managed within a database. Schemas play an important role in allowing the database objects to be organized into these logical groups.
The schema also helps in situations where the database object name is the same. But these objects fall under different logical groups.
A single schema can be used in multiple databases.
The schema also helps in adding security.
It helps in manipulating and accessing the objects which otherwise is a complex method.
You can also transfer the ownership of several schemas.
The objects created in the database can be moved among schemas.
We can quickly transfer ownership of a SQL schema to another user
We can share a schema among multiple users
It allows you to move database objects among the schemas
We get more control over database objects access and security


Steps in order to create a schema Using SQL Server Management Studio:
In object explorer, click on the databases folder.
Create the New database schema under database.
Right click Security folder, click New, select Schema.
Go on Schema-New dialog box, enter a specific name that you want to create for your new schema.
In the schema owner box, enter the name of the database user in order to own the schema. Click search, to open the Search Roles and User dialogue box.
Click OK.


How to create a Schema?
Syntax to create SQL:
CREATE SCHEMA [schema_name] [AUTHORIZATION owner_name]
[DEFAULT CHARACTER SET char_set_name]
[PATH schema_name[, ...]]
[ ANSI CREATE statements [...] ]
[ ANSI GRANT statements [...] ];


How to alter a Schema?
The schema in a database can be altered by using the alter schema statement. This statement is specifically used to rename a schema. The new owner must be a pre-existing user.
Syntax to alter a schema:
ALTER SCHEMA schema_name [RENAME TO new_schema_name] [ OWNER TO new_user_name]
Description :-
new_schema_name = new name of the schema
schema_name = existing schema
new_owner = new owner of the schema


How to drop a Schema?
In order to drop schema we use the following syntax:
DROP SCHEMA <schema name>

Razor View Engine in Asp.Net mvc

Razor view engine in asp.net mvc is the syntax that allows you to write server-side code on view. It helps to combine code and HTML in a fluid manner. Razor is not a new programming language. Razor supports C# and Visual Basic programming languages.

The Razor syntax is based on C# programming language and the code statements in Razor end with a semicolon (;) 

Syntax of Razor View Engine

Generally, in razor view engine code blocks are enclosed in "@{ ... }". Here “@” is a character that tells the beginning of Razor syntax. This code can be a single expression or an entire code block. Following syntax represents a razor view engine declaration in asp.net mvc.

@{

//Razor block

}

In the above code, the "@{" character tells the beginning of the block, and the"}" character tells the ending of the block.


Types of Block Statements in Razor

In razor, we have a different type of block statements available. Those are 

1. Single Statement Block and Inline Expression

As we discussed earlier, we will define code in opening and closing curly brackets @{...} and single statement block code will be like as shown following.

@{var Series = 4 ;}

@{var RazorMessage = "Hello Razor";}

<p> MVC series : @Series</p>

<p> Razor Message : @RazorMessage</p>


2. Multiple Statement Block and Inline Expression

In multiple statements block, we will define all variables in single curly brackets @{...}, so we need to end each variable with a semicolon. Our multiple statement block code will be as shown below.

@{

    var Title = "Welcome to Razor syntax!";

    var weekDay = DateTime.Now.DayOfWeek;

    var HomeMessage = Title + " Today is: " + weekDay;

}

<p> Razor Message : @HomeMessage</p>