我想使用Google或Facebook登录我的MVC4网络应用程序。我已经读过,取消注释AuthConfig.cs的行OAuthWebSecurity.RegisterGoogleClient()
就足以设置它但它对我不起作用。登录页面仍然显示“没有配置外部身份验证服务...”的建议,并且不显示提供程序按钮。
详细说明:
- MVC 4
- VS 2013
- 使用C#
- 使用互联网应用程序模板
---------------------------------这是我的AuthConfig.cs文件------- -----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Web.WebPages.OAuth;
using Tarea3.Models;
namespace Tarea3
{
public static class AuthConfig
{
public static void RegisterAuth()
{
// To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter,
// you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166
//OAuthWebSecurity.RegisterMicrosoftClient(
// clientId: "",
// clientSecret: "");
//OAuthWebSecurity.RegisterTwitterClient(
// consumerKey: "",
// consumerSecret: "");
//OAuthWebSecurity.RegisterFacebookClient(
// appId: "",
//appSecret: "");
OAuthWebSecurity.RegisterGoogleClient();
}
}
}
询问更多细节,谢谢!
编辑:我做了一个新项目,它只是工作正常。但我不知道我在主项目中做错了什么。它可能发生的原因是什么?
答案 0 :(得分:1)
检查您是否在Global.asax中注册Auth(类似这样:AuthConfig.RegisterAuth();)
答案 1 :(得分:0)
阅读Microsoft提供的教程,请: http://www.asp.net/mvc/tutorials/security/using-oauth-providers-with-mvc