与Facebook网站ASP.NET验证 [英] ASP.NET website authentication with facebook
问题描述
我已经看到了很多关于ASP .NET网站和Facebook之间的集成文档,但我还没有找到一个简单的工作例如,即使使用Facebook的C#SDK。
I've seen a lot of documentation about integration between ASP .NET web sites and Facebook, but I haven't found a simple working example, even using Facebook C# SDK.
我要的是一个登录与Facebook的例子,并得到用户的基本信息(如姓名,电子邮件和照片)。
All I want is a "login with Facebook" example, and to get basic user information (such as name, email and photo).
你们能帮助我吗?
非常感谢!
推荐答案
就像你说的使用Facebook的C#SDK
,那么这里就是路径和一些code帆布应用程序:
as you say using Facebook C# SDK
, then here is path and some code for canvas application:
1 - 创建从Visual Studio结果Web应用程序
2 - 安装的NuGet和的NuGet 的Facebook C#SDK
结果得到
3从 https://developers.facebook.com/apps/
创建和配置您的应用程序。结果
4-您的web配置为Facebook整合:
1- Create your web application from visual studio
2- install nuget and get by nuget Facebook C# SDK
3- from https://developers.facebook.com/apps/
create and configure your app.
4- Your web config for facebook integration :
<configuration>
<configSections>
<section name="facebookSettings" type="Facebook.FacebookConfigurationSection" />
</configSections>
<facebookSettings appId="123..." appSecret="abc...." siteUrl="http://apps.facebook.com/myapp/" canvasPage="http://app.facebook.com/myapp" secureCanvasUrl="https://myapp.com/" canvasUrl="http://myapp.com/" cancelUrlPath="http://www.facebook.com/" />
...
通过使用SDK,您可以解析签名的请求或饼干被Facebook JS SDK
By using sdk, you can parse signed request or cookie written by facebook js sdk
FacebookWebContext fbWebContext = new FacebookWebContext();
//Check if user auhtenticated
bool IsAuthenticated = fbWebContext.IsAuthenticated();
在这里,你可以通过朋友数:
Here you can have friend count by:
FacebookWebClient fbWebClient = new FacebookWebClient();
dynamic result = fbWebClient.Get("me/friends");
var friends = result["data"];
int frienCount = friends.Count;
有关客户端:
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: '123...',
status: true,
cookie: true,
xfbml: true,
oauth:true });
};
(function () {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
<!-- rest of your html -->
</body>
有关登录和放大器;问许可的JavaScript
For login & asking permission from javascript
FB.getLoginStatus(function(response) {
console.log( response );
if ((response.status)&&(response.status=='connected')) {
//successs
} else {
//user declined
}, {scope:'user_likes, offline_access'}
});
在我的项目的客户端登录我preFER因此尚未注册的用户有登陆页面,例如,如果提交表单,然后我致电上述code座。
I prefer in my project to client side login thus not yet registered user have landing page, if for example submit form then I call code block above.
请注意:您要为Internet Explorer的P3P头读取根据您的服务器/写的cookie。对于IIS,的Global.asax
:
Note: you have to set P3P header for Internet explorer to read/write cookie depending of your server. for IIS, global.asax
:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("p3p", "CP=\"CAO PSA OUR\"");
}
Volià
这篇关于与Facebook网站ASP.NET验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!