【问题标题】:Which AuthenticationType is used - Owin authentication使用哪种 AuthenticationType - Owin 身份验证
【发布时间】:2018-03-23 12:14:05
【问题描述】:

在我们的应用程序中,我们以两种不同的方式对用户进行身份验证,并且它可以正常工作。现在我想知道当用户尝试通过控制器操作访问页面并且用户已登录时使用哪个 AuthenticationType。这可能吗?

// Startup.auth.cs
    public void ConfigureAuth(IAppBuilder app)
            {
        app.UseWsFederationAuthentication(...

        app.UseOpenIdConnectAuthentication(...


   // Controller
        [AllowAnonymous]
        public ActionResult Activation()
        {
                if (!this.Request.IsAuthenticated)
                {
                    // sign in using WsFederation, works
                }
                else if (/*Signed in with OpenIdConnect AuthType*/)
                {
                    return Redirect("/");
                }

                return View();
            }

这里重要的是 els-if 语句。我可以访问 OwinContext。有没有办法知道它使用了哪个 AuthenticationType?

【问题讨论】:

    标签: c# asp.net asp.net-mvc authentication owin


    【解决方案1】:

    您可以使用此代码进行检查

    [AllowAnonymous]
    public ActionResult Activation()
    {
        if (!this.Request.IsAuthenticated)
        {
            // sign in using WsFederation, works
        }
        else if (User.Identity.AuthenticationType == "{YOUR_AUTHENTICATION_TYPE}")
        {
            return Redirect("/");
        }
    
        return View();
    } 
    

    【讨论】:

      猜你喜欢
      • 2019-02-10
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 2023-04-05
      • 1970-01-01
      • 2015-07-18
      • 2013-09-20
      相关资源
      最近更新 更多