I have a web application joined to B2C. There are the usual custom policy files setup, eg: SignUpSignIn, ChangePassword, etc. However I want to have more, eg: for a custom Registation process which has it's own custom policy file.
In the .net5 razor application, we no longer have control of the Account Controller, as this is setup for us now. In the Controller we have access to just 5 asp-actions: Challenge, EditProfile, ResetPassword, SignIn and SignOut:
In this application I have already assigned each of these to be used for other processes. Therefore how can I add another 'custom' asp-action, that I can use to call the new custom policy?
Following some investigation of the AccountController.cs file, I was able to take the code for the ResetPassword process and adapt this slightly:
var redirectUrl = $"[redirect location]";
var scheme = OpenIdConnectDefaults.AuthenticationScheme;
var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
properties.Items["policy"] = "[Name of B2C Custom Policy]";
return Challenge(properties, scheme);
After clicking on the button which runs this code, I am then directed to the B2C screen for the custom policy on the 4th line of code above.