Wednesday 10 April 2019

Virtual Networking


VNET- Customer managed secure, isolated virtual network.

·        Services and VMs that are part of VNET can access each other.

·        Each VNET can have as many subnets

·        All services deployed within a VNET can access internet

Typed of VNETs

·        Cloud only VNET

o   When a VNET created in Azure

o   VMs and services access through endpoints.

o   No configuration of VPN device required.

·        Cross premise Virtual network(Hybrid network)

o   Connection of On-Premise network with the Cloud VNET through site to site tunnel.

o   Requires a VPN device.

VNet Address space and Subnet

o   Specify Topology during VNET creation: address space and subnet

o   Private address space

§  This is the range VMs and services can use

§  Non Routable(these can’t access by public network)

§  Specified in CIDR Notation (classless inter domain routing)

·        10.0.0.0/8: 10.0.0.0 to 10.255.255.255

·        172.16.0.0/12: 172.16.0.0 to 172.31.255.255

·        192.168.0.0/16:192.168.0.0 to 192.168.255.255

o   Subnet

§  Break up the network with more manageable sections.

§  All services can access across subnets.

§  Network security groups can be utilized to implement rules .


Wednesday 3 April 2019

Visual Studio 2019 new features

The Visual Studio 2019 has been released. This release has so many features that are focused on the productivity of the developers and team collaboration, such as - better search, one-click code cleanup, debugger improvement, and management of pull requests from IDE. These are some of the core features specifically designed for improving the productivity of the dev team.


Visual Studio 2019 IDE Features and Improvements

Start Page
We will see a completely new look of VS2019 startup window. We can directly clone a repository, open an existing project, create a new project, and navigate as well as open a folder for code changes. We see a link as “Continue without code” which opens the VS2019 IDE without any solution.

Live Share
The live share enhances the developer collaboration but to use this feature, a developer must sign into Visual Studio so that the other developers would know who is sharing the information.
  • The Live Share option is available at the right-end corner.
  • The developer can sign in using a Microsoft account or Microsoft-backed school or work account.
  • By default, Visual Studio uses a personalization account for the Live Share feature though, we can change the account details for Live Share from the option, as shown in the screenshot, by navigating to Tools > Options > Live Share > User account to switch the credentials.


 

  • Click on the Live Share option to start a collaboration session. Once the Live Share environment is ready, we will see a “Sharing” menu and an invitation link copied to the clipboard that we can share with other team members to join the session.
  • A team member can join a Live Share session by navigating to “File > Join Collaboration Session” and providing the Live Share Invitation Link.





Better Search
  • This feature is dedicated to the developer's productivity. The new search is capable to search almost everything like menus, commands, options, installable components, project code, and Online as well. shortcut Cntl+Q


One-click code cleanup
  • We see a new option while opening a file which tells about the health of the file.





We can run as well as configure the code clean-up rule as per our need by right-clicking on the Health Indicator icon and choosing the “Configure Code Cleanup” opens a window to configure the customized rule.




Integrated code reviews
new extension that you can download to use with Visual Studio 2019. With this new extension, you can review, run, and even debug pull requests from your team without leaving Visual Studio. We support code in both GitHub and Azure DevOps repositoris.

Debugger improvement
We see a Search option in the Autos, Locals, and Watch window while debugging the code. By default, the search is available for three hierarchy level. As we know, complex objects have a deeper hierarchy, more than three, so that can also be configured using Settings icon in Autos, Locals and Watch window. 

https://docs.microsoft.com/en-us/visualstudio/ide/whats-new-visual-studio-2019?view=vs-2019



Tuesday 2 April 2019

What is .Net Core

.NET Core is the new open-source and cross-platform framework to build applications for all operating systems including Windows, Mac, and Linux.

Use .NET Core for your server application when:

·        You have cross-platform needs.
·        You are targeting microservices.
·        You are using Docker containers.
·        You need high-performance and scalable systems.
·        You need side-by-side .NET versions per application.

High-performance and scalable system without UI
.NET Core is much faster.
Docker containers support 
Both, but .NET Core is born to live in a container.
Heavily reply on command line
.NET Core has better support.
Cross-platform needs
.NET Core
Using Microservices
Both, but .NET Core is designed to keep today's needs in mind.
User interface centric Web applications
.NET Framework is better now until .NET Core catches up.
Windows client applications using Windows Forms and WPF
.NET Framework
Already have a pre-configured environment and systems
.NET Framework is better.
Stable version for immediate need to build and deploy
.NET Framework has a been around since 2001. .NET Core is just a baby.
Have existing experienced .NET team
.NET Core has a learning curve.
Time is not a problem. Experiments are acceptable. No rush to deployment.
.NET Core is the future of .NET.



Monday 28 January 2019

Connect to remote shared folder and copy content



net use k: $destinationFile /user:$username $password
New-Item -Path k:/$buildn -ItemType Directory -Force //create new folder in remote machine
xcopy $sourceFile k:/$buildn /E /Y /I    //Copy files to shared location
net use k: /delete

Friday 30 November 2018

Encrypt and Decrypt of Connection string in Web.config file

This article explains encryption and decryption of Connection String section of the Web.Config file using aspnet_regiis.exe Command Line Utility of the Visual Studio.


The Plain Connection Strings section in the Web.Config file
The below screenshot shows the Plain Connection Strings section in the Web.Config file before encryption.





Encrypting the Connection Strings section in Web.Config file
You need to follow the following steps for encrypting the Connection Strings section in the Web.Config file

1. Open Visual Studio Command Prompt 
You will need to open the Visual Studio Command Prompt from the Start Menu => Programs => Microsoft Visual Studio 2017 => Visual Studio Tools => Visual Studio Command Prompt.
Note: You must be log in as Administrator and right click Visual Studio Command Prompt and select Run as Administrator.
Note: In this tutorial, I am explaining the process using Microsoft Visual Studio 2010. The same process will be applicable for the other versions. The only difference will be that you need to open Visual Studio Command Prompt from the folder of the respective version of Visual Studio installed on your machine.

2. Encrypting the Connection Strings section in Web.Config using aspnet_regiis.exe tool
In order to encrypt the ConnectionString section in the Web.Config file, we will need to use the aspnet_regiis.exe tool.
Parameters
Action – It notifies the action to be performed. In order to perform Encryption, the parameter value is -pef.
Section Name – The name of the section of the Web.Config file to be encrypted. For this case, the value will be connectionStrings.
Path of the folder – Here we need to specify the path of the folder containing the Web.Config file.
Syntax
aspnet_regiis.exe -pef "connectionStrings" "<Path of the Folder containing the Web.Config file>"

Example
aspnet_regiis.exe -pef "connectionStrings" "D:\Sai\Projects\MyTestWebsite"

Note: The above command will encrypt all the Connection Strings present in the ConnectionStrings section of the Web.Config file.

Encrypted Connection Strings section in the Web.Config file
You can see Encrypted Connection Strings section in the Web.Config file after encryption.
Accessing the Encrypted Connection String value in ASP.Net Code behind
ASP.Net will automatically decrypt the Connection String when it is fetched in the code behind and hence in code behind you need to access the Connection String in the same way as you would do normally.
Decrypting the Connection Strings section in Web.Config using aspnet_regiis.exe tool 
In order to decrypt the ConnectionString section in the Web.Config file, we will need to use the same aspnet_regiis.exe tool that was used for encryption.
Parameters
Action – It notifies the action to be performed. In order to perform Decryption, the parameter value is -pdf.
Section Name – The name of the section of the Web.Config file to be decrypted. For this case the value will be connectionStrings.
Path of the folder – Here we need to specify the path of the folder containing the Web.Config file.
Syntax
aspnet_regiis.exe -pdf "connectionStrings" "<Path of the Folder containing the Web.Config file>"

Example
aspnet_regiis.exe -pdf "connectionStrings" "D:\Sai\Projects\MyTestWebsite"

Note: The above command will decrypt all the Connection Strings present in the ConnectionStrings section of the Web.Config file.

Tuesday 24 July 2018

MVC Error Handling


4 Ways to do MVC Error Handling

Between .NET, ASP.NET, and MVC there are several potential ways to handle application errors.

  • Web.Config customErrors
  • MVC HandleErrorAttribute
  • Controller.OnException method
  • HttpApplication Application_Error event

Must Have: Global Error Page With Web.Config <customErrors>
The last thing you ever want your users to see is a “yellow screen of death” type error. If you don’t know what that is, I’m referring the standard yellow ASP.NET error screen.
For any application, I would always recommend specifying a custom error page in your Web.Config. Worst case scenario, your users will see this page if an unhandled exception occurs.
<system.web>
    <customErrors mode="On" defaultRedirect="~/ErrorHandler/Index">
        <error statusCode="404" redirect="~/ErrorHandler/NotFound"/>
    </customErrors>
<system.web/>

Use MVC HandlerErrorAttribute to Customize Responses
The HandleErrorAttribute inherits from FilterAttribute and can be applied to an entire controller or individual controller action methods.
It can only handle 500 level errors that happen within an MVC action method. It does not track exceptions that help outside of the MVC pipeline. Exceptions may occur in other HTTP modules, MVC routing, etc.
When to Use HandleErrorAttribute
Since it does not provide a way to collect all exceptions that could ever happen, it is a bad solution for a global unhandled error handler.
It works perfectly for tailoring specific error pages for a specific MVC controller or action method. Specifying an error page in your Web.Config <customErrors> works ideal for a universal error page. The HandleErrorAttribute gives you fine-grained control if you need it.

Note: HandleErrorAttribute requires customErrors to be enabled in your Web.Config.
For example, if you wanted to show a particular MVC view when a SqlException happens, you can do it with the code below:
[HandleError(ExceptionType = typeof(SqlException), View = "SqlExceptionView")]
public string GetClientInfo(string username)
{            
   return "true";
}

The problem with HandleErrorAttribute is it doesn’t provide a way to log the exception!

Use MVC Controller OnException to Customize Responses
OnException is similar to HandleErrorAttribute but provides more flexibility. It works with all HTTP status codes, and not just 500 level responses. It also gives you the ability to log the errors!
public class UserMvcController : Controller
{
   protected override void OnException(ExceptionContext filterContext)
   {
      filterContext.ExceptionHandled = true;
                 //Log the error!!
      _Logger.Error(filterContext.Exception);
      //Redirect or return a view, but not both.
      filterContext.Result = RedirectToAction("Index", "ErrorHandler");
      // OR 
      filterContext.Result = new ViewResult
      {
         ViewName = "~/Views/ErrorHandler/Index.cshtml"
      };
   }
}

When to Use OnException for MVC Error Handling
If you want a way to present your users custom MVC views or custom log exceptions, OnException is a good solution for you. It provides more flexibility than HandleErrorAttribute and does not require customErrors to be enabled in your Web.Config file.
Note: OnException gets called for all HTTP status codes. So be careful how you handle simple issues like a 404 caused by a bad URL.
public class BaseController : Controller

    {

        protected override void OnException(ExceptionContext filterContext)

        {

            filterContext.ExceptionHandled = true;

            ViewData["Data"] = filterContext.Exception.Message.ToString();

            filterContext.Result = new ViewResult { ViewData = this.ViewData, ViewName = "Error" };

            base.OnException(filterContext);

        }

    }
Use HttpApplication Application_Error as Global Exception Handler
So far we have covered three different ways to customize the response that your users see if an exception occurs. Only within OnException can you potentially log exceptions.
To log all unhandled exceptions that may occur within your application, you should implement basic error logging code as shown below.
public class MvcApplication : System.Web.HttpApplication
{
   protected void Application_Start()
   {
      AreaRegistration.RegisterAllAreas();
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
      RouteConfig.RegisterRoutes(RouteTable.Routes);
      BundleConfig.RegisterBundles(BundleTable.Bundles);
   }
   protected void Application_Error()
   {
      var ex = Server.GetLastError();
      //log the error!
      _Logger.Error(ex);
   }
}
When to Use Application_Error
Always! HttpApplication’s Error even provides the best mechanism to collect and log all unhandled application errors.




Thursday 12 July 2018

Exporting & Importing Websites and AppPoll configuration between multiple IIS instances


Export the all Application Pools
The first thing you have to do is to export/import the application pools, since they will most likely be used in your web sites and you won’t be able to import those without having their relevant app pool into place. Here’s the command-line: 
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml
This command will export all your application pools – including the default ones. You’ll need to remove those, as they will most likely be in your target IIS instance with the same name and therefore they will raise a duplicate name error, blocking the whole import. In order to avoid that, open the newly created apppools.xml  file and remove the default ones such as:
·        DefaultAppPool

·        Classic .NET AppPool

·        .NET v2.0

·        .NET v2.0 Classic

·        .NET v4.5

·        .NET v4.5 Classic

Import the Application Pools
Copy the apppools.xml  file to your target webserver and run the following command:
1
%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
Each and every Application Pool mentioned in the xml file will be created on your target IIS instance.

Export the all Websites
Open up again a command-line console on your source webserver and type in the following command:
%windir%\system32\inetsrv\appcmd list site /config /xml > c:\websites.xml
Again, you’ll have to remove the default websites –  you’ll most likely have only one default website, which is Default Website – as well as any other website you don’t want to copy and/or is already existing on the target IIS instance, otherwise the import command won’t work.

Import the Websites
Just like you did with the App Pools file, copy the websites.xml  file to your target webserver and run the following command: 
%windir%\system32\inetsrv\appcmd add site /in < c:\websites.xml

Export/Import a single App Pool or Website
These commands can also be used to export/import a single application pool or a specific website. You just have to add their identifying name to the command-line, such as:
Export a specific Application Pool
%windir%\system32\inetsrv\appcmd list apppool “CustomAppPool” /config /xml > c:\customapppool.xml
Import a specific Application Pool
%windir%\system32\inetsrv\appcmd add apppool /in < c:\customapppool.xml

Export a specific Website
%windir%\system32\inetsrv\appcmd list site “CustomWebsite” /config /xml > c:\customwebsite.xml
Import a specific Website
%windir%\system32\inetsrv\appcmd add site /in < c:\customwebsite.xml

2 Using Export configuration in IIS. 
I'd say export your server config in IIS manager:
In IIS manager, click the Server node
Go to Shared Configuration under "Management"
Click “Export Configuration”. (You can use a password if you are sending them across the internet, if you are just gonna move them via a USB key then don't sweat it.)
Move these files to your new server
administration.config
applicationHost.config
configEncKey.key 
On the new server, go back to the “Shared Configuration” section and check “Enable shared configuration.” Enter the location in physical path to these files and apply them.
 It should prompt for the encryption password (if you set it) and reset IIS.