Expert Dot Net

Trust me to find new way !

ASP.NET Core Features

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. With ASP.NET Core, you can:

  • Build web apps and services, IoT apps, and mobile backends.
  • Use your favorite development tools on Windows, macOS, and Linux.
  • Deploy to the cloud or on-premises
  • Run on .NET Core or .NET Framework.

Why use ASP.NET Core?

Millions of developers have used ASP.NET (and continue to use it) to create web apps. ASP.NET Core is a redesign of ASP.NET, with architectural changes that result in a leaner and modular framework.2

ASP.NET Core provides the following benefits:

  • A unified story for building web UI and web APIs.
  • Integration of modern client-side frameworks and development workflows.
  • A cloud-ready, environment-based configuration system.
  • Built-in dependency injection.
  • A lightweight, high-performance, and modular HTTP request pipeline.
  • Ability to host on IIS or self-host in your own process.
  • Can run on .NET Core, which supports true side-by-side app versioning.
  • Tooling that simplifies modern web development.
  • Ability to build and run on Windows, macOS, and Linux.
  • Open-source and community-focused.


ASP.NET Core ships entirely as NuGet packages. This allows you to optimize your app to include just the NuGet packages you need. The benefits of a smaller app surface area include tighter security, reduced servicing, and improved performance.2

Build web APIs and web UI using ASP.NET Core MVC

ASP.NET Core MVC provides features that help you build web APIs and web apps:

  • The Model-View-Controller (MVC) pattern helps make your web APIs and web apps testable.
  • Razor Pages (new in 2.0) is a page-based programming model that makes building web UI easier and more productive.
  • Razor syntax provides a productive language for Razor Pages and MVC Views.
  • Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files.
  • Built-in support for multiple data formats and content negotiation lets your web APIs reach a broad range of clients, including browsers and mobile devices.
  • Model Binding automatically maps data from HTTP requests to action method parameters.
  • Model Validation automatically performs client and server-side validation.

Client-side development

ASP.NET Core is designed to integrate seamlessly with a variety of client-side frameworks, including AngularJS, KnockoutJS, and Bootstrap. See Client-side development for more details.

Learn ASP.NET MVC Filters and Attributes

In ASP.NET MVC, controllers define action methods and these action methods generally have a one-to-one relationship with UI controls, such as clicking a button or a link, etc. For example, in one of our previous examples, the UserController class contained methods UserAdd, UserDelete, etc.


However, many times we would like to perform some action before or after a particular operation. For achieving this functionality, ASP.NET MVC provides a feature to add pre- and post-action behaviors on the controller's action methods.


Types of Filters

ASP.NET MVC framework supports the following action filters −


  1. Action Filters − Action filters are used to implement logic that gets executed before and after a controller action executes. We will look at Action Filters in detail in this chapter.
  2. Authorization Filters − Authorization filters are used to implement authentication and authorization for controller actions.
  3. Result Filters − Result filters contain logic that is executed before and after a view result is executed. For example, you might want to modify a view result right before the view is rendered to the browser.
  4. Exception Filters − Exception filters are the last type of filter to run. You can use an exception filter to handle errors raised by either your controller actions or controller action results. You also can use exception filters to log errors.


Action filters are one of the most commonly used filters to perform additional data processing, or manipulating the return values or cancelling the execution of action or modifying the view structure at run time.


Action Filters

Action Filters are additional attributes that can be applied to either a controller section or the entire controller to modify the way in which an action is executed. These attributes are special .NET classes derived from System.Attribute which can be attached to classes, methods, properties, and fields.


ASP.NET MVC provides the following action filters −


  1. Output Cache − This action filter caches the output of a controller action for a specified amount of time.
  2. Handle Error − This action filter handles errors raised when a controller action executes.
  3. Authorize − This action filter enables you to restrict access to a particular user or role.


Now, we will see the code example to apply these filters on an example controller ActionFilterDemoController. (ActionFilterDemoController is just used as an example. You can use these filters on any of your controllers.)


Output Cache

Example − Specifies the return value to be cached for 10 seconds.

Visual Studio 2017 New Feature

Visual Studio 2017 New Feature

1 - Visual Studio 2017 Installer

Visual Studio 2017 comes with a brand new, revamped installer. I have never been a fan of the previous Visual Studio installers. It literally took forever to install Visual Studio. It was, in my opinion, a very painful experience and I dreaded every time I had to install a new version of Visual Studio. Now, the process is far less painful.

The new installer for Visual Studio 2017 has the following features:

  • Installs more quickly with less system impact.
  • Uninstalls cleanly.
  • Reduces the footprint of Visual Studio.
  • Makes it easier for you to select and install just the features you need.


2 - A New Visual Studio Start Page

The new Visual Studio 2017 Start Page has new Open and Create facilities, including:

  • Updated badge on newly added items in the News Feed.
  • Dismissible "Get Started" section.
  • The Visual Studio 2017 Start Page Most Recent Used items (MRU) shows repos that you have cloned on other machines so that you can easily clone them on your current machine.
  • Create new projects directly from the Start Page with searchable templates and a list of recently used templates.
  • Refined visual design to address feedback about truncated elements on smaller screens and utilization of empty space.

3 - New Extensibility Features
The new Visual Studio 2017 installer gives you greater control over the tools that are installed. Users will be warned when attempting to install an extension that was not built using the new VSIX format.

4 - Live Unit Testing
Live Unit Testing visualizes unit test results and code coverage live on the editor, as you are coding. It works with C# and VB projects and supports three test frameworks: MS Test, xUnit, and NUnit. Currently, Live Unit Testing is only present in the Enterprise edition of Visual Studio 2017.

5 - Run to Click Debugging
You can simply click the icon next to a line of code whilst debugging to run to that line. You no longer have to set temporary breakpoints or perform several steps to execute your code and stop on the line you want.

6 - The New Visual Studio 2017 Exception Helper
  • You can use the new Exception Helper in Visual Studio 2017 to view exception information in a compact, non-modal dialog with instant access to inner exceptions.
  • Quickly see what was null inside the Exception Helper when diagnosing a NullReferenceException.
  • You can exclude breaking on exception types thrown from specific modules.

7 -  Language Extensions

C#
  • Task-like return types for async methods.
  • Value tuples that introduce language support for using tuples to temporarily group a set of typed values.
  • Nested local functions that support declaration of functions in a block scope.
  • Pattern matching extensions.
  • Ref returns that enable functions to return values by reference.
Visual Basic
  • Value tuples; for example: Dim point As (x As Integer, y As Integer) = GetOffset().
  • ByRef return consumption supports consumption of functions and properties from libraries that have ByRef returns.
  • Binary literals and digit group separators allow native representation of binary numbers.

SQL Server 2016 new features

SQL Server 2016 is the biggest leap forward in Microsoft data platform history. There is a lot of buzz around SQL Server 2016. Gain real time insights across your transaction and analytical data with a salable database platform that has everything built in, from unparalleled in-memory performance, new security innovations and high availability, to advanced analytics that make mission-critical applications intelligent.

Always Encrypted -   SQL Server 2016 has introduced new feature that is Always Encrypted. If this feature is enabled in your SQL Server then all data would be in encrypted mode always. By this feature all the confidential data would be save and we can apply proper access control of data in proper mode.

Dynamic Data Masking - This is very interesting feature of SQL Server 2016 edition. If you want to hide some part of any data to be hidden by for some one and some part to be shown to some one then easily you can make this done using this feature. e.g. you have mobile number stored in database and you want to hide all digits except last 2 digits then easily you can perform this using Dynamic Data Masking feature.

JSON Support - JSON stands for Java Script Object Notation. Now using this feature of SQL Server 2016 you can easily interchange the data in JSON format.

TempDB Database Files -  During setup, you can configure the number of tempdb database files, initial size, auto growth and directory placement using the new UI input control on the Database Engine Configuration - TempDB section of SQL Server Installation Wizard.

Query Store - If you are into examining execution plans than you will like the new Query Store feature. Currently in versions of SQL Server prior to 2016 you can see existing execution plans by using dynamic management views (DMVs). But, the DMVs only allow you to see the plans that are actively in the plan cache. You can’t see any history for plans once they are rolled out of the plan cache. With the Query Store feature, This is a great addition and will allow you to now track execution plans performance for your queries over time. 

Row Level Security -  You can apply row level security in SQL Server 2016

 

C# For Loop

Loop is used in programming when you need to repeat any group of statement or statement more then one time. For loop is one important looping construct which is used to iterate set of instructions.


for ( int i=0 ; i <= 5 ; i++)

{

// Your statements

}


There are 4 parts of this for loop.


- First part is initialization

- Second part is condition checking

- Third part is increment / decrements

- Fourth part is group of statements which basically would be executed.


Demo 1 :




New Features introduces in .NET 4.5 and 5.0

C# evolution look in a glance : 


1. Parallel.ForEach

Parallel.ForEach is a feature introduced by the Task Parallel Library (TPL). This feature helps you run your loop in parallel. You need to have a multi-processor to use of this feature.

Simple foreach loop

foreach (string i in listStrings)
{
// put your statement here
}

Parallel foreach

Parallel.Foreach(listStrings, text=>
{
// put your statement here
});

2. BigInteger

BigInteger is added as a new feature in the System.Numerics DLL. It is an immutable type that represents a very large integer whose value has no upper or lower bounds.

BigInteger obj = new BigInteger("123456789123456789123456789");


3. ExpandoObject

The ExpandoObject is part of the Dynamic Language Runtime (DLR). One can add and remove members from this object at run time.

Create a dynamic instance.

dynamic Person = new ExpandoObject();
Person.ID = 1001;
Person.Name = "Princy";
Person.LastName = “Gupta”; 

4. Named and Optional Parameters

Optional Parameters

A developer can now have some optional parameters by providing default values for them. PFB how to create optional parameters.

Void PrintName(string a, string b, string c = “princy”)
{
     Console.Writeline(a, b, c)
}
We can now call the function PrinctName() by passing either two or three parameters as in the following:

PrintName(“Princy”,”Gupta”,”Jain”);
PrinctName(“Princy”,”Gupta”);

Output

PrincyGuptaJain
PrincyGuptaprincy

Note: An optional parameter can only be at the end of the parameter list.

Named Parameters

With this new feature the developer can pass values to parameters by referring to parameters by names.

Void PrintName(string A, string B
{
}
Function call

PrintName (B: “Gupta”, A: “Princy”);

With this feature we don't need to pass parameters in the same order to a function.

5. Tuple

A Tuple provides us the ability to store various types in a single object.

The following shows how to create a tuple.

Tuple<int, string, bool> tuple = new Tuple<int, string, bool>(1,"princy", true);
Var tupleobj = Tuple.Create(1, "Princy", true); 
In order to access the data inside the tuple, use the following:

string name = tupleobj.Item2;
int age = tupleobj.Item1;
bool obj = tupleobj.Item3;

6. Compiler APIs 

 This feature is supposed to come after C# 5.0 – the APIs will expose whatever knowledge the compiler has about the code to the IDE and the developers, through Syntax Tree APIs, Symbol APIs, Binding and Flow analysis APIs and Emit APIs.

You can use following References for more details.

7. Windows Runtime Support

C# and .NET now have deep integration with the Windows Runtime. C# project can compiled into a WinMD file and then referenced from a HTML/JavaScript project. WinRT’s flavor of COM uses the same metadata format used by the Common Language Runtime. This information is stored in WINMD files that show the structure, though not the implementation, of all the public classes. Windows Runtime returns an HRESULT instead of throwing an exception. For well-known HRESULT values, the corresponding exception is thrown, otherwise a COMException is used.

Not able to install SqlServer 2008 says Restart computer failed

When you are trying to install SQL server on your computer and because of any other installation or any process some files are pending for renaming hence this happened.




Steps to solve this problem

- Open the run window

- Type regedit to open  registry editor.

- Search for following value in registry.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

- Double click the PendingFIleRenameOperations and once you will double click it a dialog window would be appeared and simply press the delete key and click OK

Now you would be able to install your SQL server. Please leave your comments if this post helps you.


LINQ Aggregate and Sum

using System;

using System.Linq;

using System.Collections;

using System.Collections.Generic;

 

public class LINQDemo4 {

    public static void Main() {

        IEnumerable<int> intSequence = Enumerable.Range(1, 10);

        foreach (int item in intSequence)

            Console.WriteLine(item);

        int sum = intSequence.Aggregate(0, (s, i) => s + i);

        Console.WriteLine(sum);

    }

}

 

LINQ Aggregate Prototype

using System;

using System.Linq;

using System.Collections;

using System.Collections.Generic;

 

public class LINQDemo3 {

    public static void Main() {

        int N = 5;

        IEnumerable<int> intSequence = Enumerable.Range(1, N);

        foreach (int item in intSequence)

            Console.WriteLine(item);

        int agg = intSequence.Aggregate((av, e) => av * e);

        Console.WriteLine("{0}! = {1}", N, agg);

 

    }

}