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);
}
}
}
}
}