使用哪种 AuthenticationType - Owin 身份验证
Which AuthenticationType is used - Owin authentication
在我们的应用程序中,我们以两种不同的方式对用户进行身份验证,并且它可以正常工作。现在我想知道 当用户尝试通过控制器操作访问页面并且用户已登录时使用哪个 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?
您可以使用此代码进行检查
[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();
}
在我们的应用程序中,我们以两种不同的方式对用户进行身份验证,并且它可以正常工作。现在我想知道 当用户尝试通过控制器操作访问页面并且用户已登录时使用哪个 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?
您可以使用此代码进行检查
[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();
}