ASP.NET4 canvas应用:回发导致意外的重定向 [英] ASP.NET4 canvas app: Postback causes unexpected redirect

查看:41
本文介绍了ASP.NET4 canvas应用:回发导致意外的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用该工具包的内部版本5.06,而我刚刚开始,尝试做一些简单的事情:使回发工作.但是,当用户单击回发"按钮时,浏览器将快速重定向到某个东西(我认为它是uiserver.???),然后再次重定向到facebookredirect.axd,最后再次重定向到我的主画布页面.因此,整个会话几乎都已重置.我希望有一些明显的我想念的东西(比如我不应该在回发中打电话给Authorize吗?).这是我的代码:

I'm using build 5.06 of the toolkit and I'm just getting started, trying to do something simple: get a postback to work. But when the user clicks the postback button, the browser is redirected to something quickly (I think it's uiserver.???) and then redirected again to facebookredirect.axd, and finally again to my home canvas page. So, the entire session is pretty much reset. I'm hoping there's something obvious that I'm missing (like I should not call authorize on the postback?). Here's my code:

使用系统; 使用System.Configuration; 使用System.Web.UI; 使用Facebook; 使用Facebook.Web;

using System; using System.Configuration; using System.Web.UI; using Facebook; using Facebook.Web;

公共局部类_Default:页面 {

public partial class _Default : Page {

/// <summary>
/// Gets the current canvas facebook session.
/// </summary>
public FacebookSession CurrentSession
{
    get { return (new CanvasAuthorizer()).Session; }
}

protected void Page_Load(object sender, EventArgs e)
{

    var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me" } };

    if (auth.Authorize())
    {
        ShowFacebookContent();
    }
}

private void ShowFacebookContent()
{
    var fb = new FacebookClient(this.CurrentSession.AccessToken);
    dynamic myInfo = fb.Get("me");
    lblName.Text = myInfo.name;
    lblName.Text += myInfo.gender;
    pnlHello.Visible = true;
}


protected void TempSaveButton_Click(object sender, EventArgs e)
{
    var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me" } };
    if (auth.Authorize())

    {
        var fb = new FacebookClient(this.CurrentSession.AccessToken);
        dynamic myInfo = fb.Get("me");
        lblDisplayText.Text = "Was authorized! name is" + myInfo.name;
    }
    else
    {
        lblDisplayText.Text = "Was not authorized!";
    }
}

}

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">


</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">


<asp:Label runat="server" ID="a" />
<asp:Panel ID="pnlHello" runat="server" Visible="false">    </asp:Panel>
    <h2>
        Hello
        <asp:Label ID="lblName" runat="server" />!
         </h2>   
        <div>Hello ! Please press button to do postback.

<asp:Button ID="TempSaveButton" Text="Temp Save" runat="server" onclick="TempSaveButton_Click"></asp:button>



<asp:Panel ID="pnlError" runat="server" Visible="false">
    <a href="Default.aspx">
        <asp:Label ID="lblDisplayText" runat="server" ForeColor="Red" /><br />
    </a>
</asp:Panel>

(在上述情况下,回发后标签完全没有设置.

(in the above, the label does not get set at all after the postback.

感谢您的帮助...

-本

推荐答案

对于回发和ajax请求,您将需要手动维护signed_request.

You will need to maintain the signed_request manually for postbacks and ajax requests.

尝试创建一个包含signed_request的隐藏输入字段.

Try creating a hidden input field which contains the signed_request.

<input type="hidden" name="signed_request" value="<%: Request.Params["signed_request"]%>"/>

将隐藏字段命名为signed_request.因此,当您键入以下代码时,将自动设置access_token.

Name the hidden field signed_request. So when you type the following code, access_token is automatically set.

var fb = new FacebookWebClient();

对于mvc,有一个辅助方法.

For mvc there is a helper method for this.

@Html.FacebookSignedRequest()

这篇关于ASP.NET4 canvas应用:回发导致意外的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆