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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s