How to Bypass Login Credentials for Debugging & Integration Test purposes in ASP.NET MVC?

While debugging ASP.NET MVC applications often we need to Bypass login credentials to accelerate the debugging process. You can wrap the following code inside a Debugger.IsAttached block and invoke during the Login action – preferably on the Login button click Or authentication invoker area.

var claims = new List<Claim>

{

new Claim(“name”, “Developer”),

new Claim (“email”, “email@domain.com”)

};

var claimsIdentity = new claimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

var authProperties = new AuthenticationProperties

{

AllowRefresh = true,

ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(600), // Too far

IsPersistent = true,

IssuedUtc = DateTime.UtcNow,

};

await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);

// Redirect

HttpContext.Rsponse.Rediret(“yourUrl”);