私の要件では、Facebookログインボタンを追加して、ユーザーがFacebook資格情報で認証できるようにする必要があります。ログインページのFacebookログインボタンをC#mvc4に追加します。
私は多くのリンクをGoogleで検索しかし、私が見つけた私の要件はありませんMVCが提供するデフォルトのログインページに、私のログインページにFacebookのボタンを追加し、何であるか
を下回っています。
は、私は1つ便利なものを見つけましたが、そのは例外 PFB私は私はそれを解決することはできませんよのActionResult Facebookの()内のいくつかのエラーを取得していますpublic class AccountController : Controller
{
private Uri RedirectUri
{
get
{
var uriBuilder = new UriBuilder(Request.Url);
uriBuilder.Query = null;
uriBuilder.Fragment = null;
uriBuilder.Path = Url.Action("FacebookCallback");
return uriBuilder.Uri;
}
}
[AllowAnonymous]
public ActionResult login()
{
return View();
}
public ActionResult logout()
{
FormsAuthentication.SignOut();
return View("Login");
}
[AllowAnonymous]
public ActionResult Facebook()
{
var fb = new FacebookClient();
var loginUrl = fb.GetLoginUrl(new
{
client_id = "444195149059600",
client_secret = "89223ca2d87cc4a741000d5c1ea57694",
redirect_uri = RedirectUri.AbsoluteUri,
response_type = "code",
scope = "email" // Add other permissions as needed
});
return Redirect(loginUrl.AbsoluteUri);
}
public ActionResult FacebookCallback(string code)
{
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = "444195149059600",
client_secret = "89223ca2d87cc4a741000d5c1ea57694",
redirect_uri = RedirectUri.AbsoluteUri,
code = code
});
var accessToken = result.access_token;
// Store the access token in the session for farther use
Session["AccessToken"] = accessToken;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
string email = me.email;
string firstname = me.first_name;
string middlename = me.middle_name;
string lastname = me.last_name;
// Set the auth cookie
FormsAuthentication.SetAuthCookie(email, false);
return RedirectToAction("Index", "Home");
}
}
}
を参照のうえ午前のコードを投げます。 同じことを教えてもらえますか?高度な
ショーが詳細にそこに遭遇したようなので、お使いの外部ログインで
スタートアップクラスには、メソッドを持っています。 –