我一直在关注这个例子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);
}
您获得的通知
参数包含您需要了解的有关最终用户及其成功身份验证的所有信息。
关于Azure 事件目录 : Where can I insert a function to run after a user is signed in?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36995367/