我一直在遵循这个例子https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-devquickstarts-web-dotnet/我很确定,在SignIn
方法中,我可以把我的函数放在那里运行,但我不确定你会如何进行
在AccountController.cs示例的顶部:
namespace WebApp_OpenIDConnect_DotNet_B2C.Controllers
{
public class AccountController : Controller
{
public void SignIn()
{
if (!Request.IsAuthenticated)
{
// To execute a policy, you simply need to trigger an OWIN challenge.
// You can indicate which policy to use by adding it to the AuthenticationProperties using the PolicyKey provided.
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties (
new Dictionary<string, string>
{
{Startup.PolicyKey, Startup.SignInPolicyId}
})
{
RedirectUri = "/",
}, OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
在哪里插入toDoAfterSignedIn();方法或者这是错误的方法吗?当用户成功登录时,是否有某个监听器或事件发射器会通知我?
https://github.com/AzureADQuickStarts/B2C-WebApp-OpenIdConnect-DotNet
正确的插件位置是Startup.Auth.cs文件。并注册一个OpenIdConnectNotifications
。您需要的通知是SecurityTokenValidated
。您需要将其添加到示例中已经存在的其他两个通知中。或者只需在OpenIdConnectnotifications
初始值设定项中添加以下行:
SecurityTokenValidated = (notification) => {
return Task.Delay(0);
}
您获得的notification
参数包含您需要了解的有关最终用户及其成功身份验证的所有信息。