Вот пример кода о том, как защитить страницу с именем ProtectedPage.aspx и создать страницу входа с именем LogOn.aspx:
Login.aspx:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Log In
</h2>
<p>
<fb:login-button></fb:login-button>
</p>
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: 'your app id', status: true, cookie: true, xfbml: true });
FB.Event.subscribe('auth.sessionChange', function (response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
window.location.reload();
} else {
// The user has logged out, and the cookie has been cleared
}
});
</script>
</asp:Content>
Login.aspx.cs
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FacebookApp app = new FacebookApp();
Authorizer authorizer = new Authorizer(app);
if (authorizer.IsAuthorized())
{
Response.Redirect(HttpUtility.UrlDecode(Request.QueryString["returnUrl"] ?? "/"));
}
}
}
ProtectedPage.aspx.cs
public partial class ProtectedPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FacebookApp app = new FacebookApp();
Authorizer authorizer = new Authorizer(app);
if (!authorizer.IsAuthorized())
{
Response.Redirect("~/Account/Login.aspx?returnUrl=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery));
}
}
}
На нашей Codeplex wiki .
есть больше примеров и образцов.