本文介绍了在Razor视图中找不到AuthenticationManager.GetExternalLoginInfoAsync()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的mvc5应用程序中使用外部登录提供程序.在我的控制器中,我可以使用下面的方法检查是否有任何外部登录信息
I am using External Login providers in my mvc5 application.In my controller I can use below to check if there is any external login info
await AuthenticationManager.GetExternalLoginInfoAsync();
如何在剃须刀视图中使用它来检查是否存在外部登录信息.我在下面使用
How can I use this in my razor view to check if external login info exists or not. I used below
if (HttpContext.Current.GetOwinContext()==null)
{
...............
}
哪个似乎有效,但
即使注销也仍然不为空我需要在ExternalLogInConfirmation页面上显示/隐藏一些信息,取决于它
still not null even after logoutI need to show/hide some information depending on it in the ExternalLogInConfirmation Page
推荐答案
我为此创建了一个扩展方法
I have created an extension method for this
namespace MyApp.ExtensionMethods
{
public static class Extentions
{
public static bool IsExternalLogInfoExists(this IPrincipal principal)
{
return HttpContext.Current.GetOwinContext().
Authentication.GetExternalLoginInfo()==null?false:true;
}
}
}
然后在我看来
if (!User.IsExternalLogInfoExists())
{
//show/hide any thing
}
当然,您首先需要添加名称空间.就我而言
Of course on top you need add namespace. On my case
@using MyApp.ExtensionMethods;
这篇关于在Razor视图中找不到AuthenticationManager.GetExternalLoginInfoAsync()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!