表单提交与Facebook C#SDK [英] Form Post with Facebook C# SDK

查看:149
本文介绍了表单提交与Facebook C#SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以点我的我该如何使用表单POST与Facebook的C#SDK在MVC应用程序的方向?这是一个基于iframe画布的应用程序。

Can anyone point me in the direction of how I can use a form post with the Facebook C# SDK in an MVC app? It's an iframe based Canvas application.

我有以下代码

[HttpPost, CanvasAuthorize(Permissions = "publish_stream")]
public ActionResult Enter(FormCollection col)
{
    var fbApp = new FacebookClient(this.CurrentSession.AccessToken);

    JsonObject result = (JsonObject)fbApp.Get("me");

    long FacebookId = long.Parse(result["id"].ToString());

    //CODE TO INSERT GOES HERE

     return View();
}

和形式是这样的。

<form action="/EnterComp/Enter" enctype="multipart/form-data" method="post">
<fieldset>
    <legend>Fields</legend>
    <div class="editor-label">
        <label for="Text">Text</label>

    </div>
    <div class="editor-field">
        <input id="Text" name="Text" type="text" value="" />

    </div>
    <div class="editor-label">
        <label for="ImagePath">ImagePath</label>
    </div>
    <div class="editor-field">

        <input type="file" name="ImagePath" id="ImagePath">

    </div>
    <div class="editor-label">
        <label for="VideoPath">VideoPath</label>
    </div>
    <div class="editor-field">
        <input type="file" name="VideoPath" id="VideoPath">

    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
</form>



但每次我提交表单,它似乎要重新验证 - 从而失去形式的集合。现在,我敢肯定有很简单的东西我错过了,任何帮助,将不胜感激。

But everytime I submit the form, it appears to re-authenticate - and thus lose the form collection. Now I'm sure there's something really simple I'm missing, any help would be appreciated.

修改

我想我已经在这里找到答案我自己的问题,但如果其他人我照顾。解决的办法,至少对我来说,是 rel=\"nofollow\">。

I think I've answered my own question here, but in case anyone else after me looks. The solution, for me at least, was here.

不过,如果任何人都可以提出任何东西。请帮助!

However, if anyone can suggest anything else. Please help!

推荐答案

有实际上是MVC的形式,将解决这个问题,为你的帮手。

There is actually a helper for MVC forms that will fix this issue for you.

助手去你的表单中:

剃刀语法:

@Html.FacebookSignedRequest();



ASP.NET语法

ASP.NET Syntax

<%=Html.FacebookSignedRequest() %>

这一切实际上,它只是你signed_requeset保存为隐藏窗体上。这样,当表单发布Facebook的身份验证就可以重新授权请求。

All this actually does is store your signed_requeset as a hidden on your form. This way when the form is posted the Facebook authenticator will be able to reauthorize the request.

这篇关于表单提交与Facebook C#SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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