Monday, February 10, 2020

How to add a virtual directory..

Before adding a virtual directory we need to add authentication in two applications authentication web.server starting.
It will only work if it's in this order

Custom Registration In ASP.NET MVC

1.Add new properties
click Ctrl + F and find "ApplicationUser : IdentityUser"

public class ApplicationUser : IdentityUser
    {
        //New properties
        public string FirstName { get; set; }

        public string LastName { get; set; }
        // existing code
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }
    }
2.Find out "public class RegisterViewModel"
Add new properties in this model
        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "First Name")]
        public string FirstName { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "Last Name")]
        public string LastName { get; set; }

3.find out "public async Task<ActionResult> Register(RegisterViewModel model)"
Add properties in

var user = new ApplicationUser
{
UserName = model.Email,
Email = model.Email,
FirstName = model.FirstName, //new property
LastName = model.LastName    //new property
};

and build application

4. Goto Tools > NuGet Package Manager > Click "Package Manager Console"
Now add the following commands in Console Manager
  1. Enable-Migrations

  2. Add-Migration UpdateTable

  3. Update-Database –verbose

Build and Run the application


an unhandled exception of type 'system.typeinitializationexception' occurred in c# (or) web.config

Solution: Check once the web.config file. Case sensitive Issue

<configsections> to <configSections>
<appsettings> to <appSettings>

Chain of Responsibility Design Pattern


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Management management = new Management(null);
Exp exp = new Exp(management);
Employee emp = new Employee(exp);
emp.HandleRequest(30000);
emp.HandleRequest(25000);
emp.HandleRequest(10000);
Console.ReadLine();
}
public interface Ihandle
{
void HandleRequest(int id);
}
public class Employee :Ihandle
{
Ihandle _handle;
public Employee(Ihandle handle)
{
this._handle = handle;
}
public void HandleRequest(int id)
{
if (id > 1000 && id <= 10000)
{
Console.WriteLine("Fresher");
}
else if (this._handle != null)
{
this._handle.HandleRequest(id);
}
}
}

public class Exp : Ihandle
{
private Ihandle _handle;
public Exp(Ihandle handle)
{
this._handle = handle;
}
public void HandleRequest(int id)
{
if(id>=10001 && id<=20000)
{
Console.WriteLine("Experienced");
}
else if(this._handle!=null)
{
this._handle.HandleRequest(id);
}
}
}
public class Management : Ihandle
{
Ihandle _handle;
public Management(Ihandle handle)
{
this._handle = handle;
}
public void HandleRequest(int id)
{
if(id>=20001 &&id <= 30000)
{
Console.WriteLine("Management");
}
else if(this._handle!=null)
{
this._handle.HandleRequest(id);
}
}
}
}
}


Wednesday, February 5, 2020

Interface with real time Example


Interface means a class that has no implementation of its method, but with just declaration. Other hand, abstract class is a class that can have implementation of some method along with some method with just declarationno implementation.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
//interface no implementation only declaration
internal interface interfaceName
{
int GetSalary();
}
public class Fresher : interfaceName
{
public int GetSalary()
{
return 10000;
}
}
public class ExpSalary : interfaceName
{
public int GetSalary()
{
return 20000;
}

}
internal class Program
{
public static void Main(string[] args)
{
Fresher fresher = new Fresher();
int fresherSal = fresher.GetSalary();
Console.WriteLine(fresherSal.ToString());
ExpSalary exp = new ExpSalary();
int expSal = exp.GetSalary();
Console.WriteLine(expSal.ToString());
Console.ReadLine();
}
}
}


Abstract with real time Example


Abstract methods implementation and non-implementation method like

Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
//Abstart methods implemetation and non implemetation method like

//abstract Class
public abstract class AbstractClass
{
public abstract void salary();

public void GetEmpName()
{
Console.WriteLine("Naresh");
}


}

//derived class

public class FresherSalary : AbstractClass //inheriting from abstract class
{
public override void salary()

{
Console.WriteLine("Fresher Salary = 10000");
}

}

public class ExpSalary : AbstractClass //inherting from abstract class

{
public override void salary()
{
Console.WriteLine("Exp salary = 20000");
//Console.ReadLine();
}

}

internal class Program
{
public static void Main(string[] args)
{
FresherSalary fresher = new FresherSalary(); //Creating object for fresher
fresher.salary();
ExpSalary exp = new ExpSalary();
exp.salary();
//and calling implemented method in abstart class
exp.GetEmpName();
Console.ReadLine();
}
}
}


What is difference between DTO and POCO classes in VS

POCO- Plain Old CLR (or) Class Object

public class Employee
{
    public int Id {get;set;}
    public string FirstName{get;set;}
    public void Salary()
    { 
        Console.WriteLine("10000");
    }
}
DTO -no behaviour - Data Transfer Object

public class EmployeeDTO
{
    public int Id {get;set;}
    public string FirstName {get;set;}
}

Friday, December 13, 2019

Issue: Visual Studio Displaying integer values in hexadecimal

Solution: Debugging time Go To quick watch in a visual studio And right-click quick watch and unselect hexadecimal

Friday, June 28, 2019

Nuget package Generation for customized DLL

first download "nuget.exe"

open cmd and change the path to  particular folder in which "nuget.exe" is downloaded.

generate nuspec file using folling command - nuget spec "E:\Naresh\proj.csproj"

package -  it will generate this type of file like proj.csproj.nuspec

edit that file to make necessary changes like below


<?xml version="1.0"?>
<package >
  <metadata>
    <id>proj</id> // project name
    <version>1.0.0</version>
    <authors>Naresh</authors>
    <owners>Naresh</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2019</copyright>
    <tags>Tag1 Tag2</tags> // no need
    <dependencies>
      <dependency id="SampleDependency" version="1.0" /> //no need of samples
    </dependencies>
  </metadata>
  <files>
    <file src="E:\Naresh\proj\bin\Debug\*.*" target="lib\net461" /> // main project file to package - means debug location
  </files>
</package>


we need build the package based on that nuspec file- example cmd path E:\download> nuget pack proj.csproj.nuspec

done...

application goto project manage nuget packages - settings - add one available package source - + click and set the path to nuget package in our local system. goto manage and we will see the new package source.. njoyyyy.. by Vasista Bhargav

How to change a DLL version ?

1. Right click on your project. 
2. Click properties. 
3. Go to the Application tab. 
4. Click Assembly Information. 
5. Change Assembly Version or / and File Version. 
6. Click OK. 
7. Click the save button. 
8. Recompile 
this is one way... njoyyyy.. by Vasista Bhargav