使用 SimpleMembership,您可以向外部身份验证提供程序按钮添加一个图标,如下所示:
简单会员制:
Dictionary<string, object> FacebooksocialData = new Dictionary<string, object>();
FacebooksocialData.Add("Icon", "/content/images/gui/loginFacebook.png");
OAuthWebSecurity.RegisterFacebookClient(
appId: "x",
appSecret: "x",
displayName: "Facebook",
extraData: FacebooksocialData);
然后在您的视图中像这样显示它们:
@foreach (AuthenticationClientData p in Model)
{
<button class="externalLoginService" style="cursor:pointer;color:transparent;border:none;background:url(@p.ExtraData["Icon"]);width:94px;height:93px;margin-right:20px;" type="submit" name="provider" value="@p.AuthenticationClient.ProviderName" title="Log in with @p.DisplayName">@p.DisplayName</button>
}
ASP.NET 身份(?):
app.UseFacebookAuthentication(
appId: "x",
appSecret: "x");
如何使用 ASP.NET Identity(控制器和视图)实现同样的事情?
另一种方法:
摘取了这个博客中的一些内容(使用了 zocial 图标,但我发现这些图标太过分了 - 请参阅 css 文件,您就会知道我的意思):http://www.beabigrockstar.com/pretty-social-login-buttons-for-asp-net-mvc-5/ http://www.beabigrockstar.com/pretty-social-login-buttons-for-asp-net-mvc-5/
并这样做了:
Startup.Auth.cs
(没有额外的东西,只是 MVC 5 应用程序中的标准默认内容)
app.UseFacebookAuthentication(appId: "x", appSecret: "x");
app.UseGoogleAuthentication();
CSS:
.socialLoginButton {
cursor:pointer;color:transparent;border:none;width:94px;height:93px;margin-right:20px;
}
.socialLoginButton.facebook {
background:url(/content/images/gui/loginFacebook.png);
}
.socialLoginButton.google {
background:url(/content/images/gui/loginGoogle.png);
}
View:
<button type="submit" class="externalLoginService socialLoginButton @p.AuthenticationType.ToLower()" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in with @p.Caption">@p.AuthenticationType</button>
使用类而不是上面其他解决方案/答案中不太优雅的样式属性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)