CanvasAuthorize和VerificationException

时间:2011-05-15 20:42:11

标签: facebook-c#-sdk

我正在执行这段代码:

    [CanvasAuthorize(Permissions = "user_about_me")]
    public ActionResult About()
    {
        var fb = new FacebookWebClient();

        dynamic result = fb.Get("me");

        ViewData["Firstname"] = result.first_name;
        ViewData["Lastname"] = result.last_name;


        return View();
    }

我得到以下异常......有什么想法吗?

'/'应用程序中的服务器错误。

操作可能会破坏运行时的稳定性。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Security.VerificationException:操作可能会破坏运行时的稳定性。

来源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

堆栈追踪:

[VerificationException:操作可能会破坏运行时的稳定性。]    SimpleJson.SimpleJson.ParseValue(Char [] json,Int32&amp; index,Boolean&amp; success)+107    SimpleJson.SimpleJson.TryDeserializeObject(String json,Object&amp; object)+212    SimpleJson.SimpleJson.DeserializeObject(String json)+84    Facebook.SimpleJsonSerializer.DeserializeObject(String json)+112    Facebook.FacebookSignedRequest.TryParse(String secret,String signedRequestValue,Int32 maxAge,Double currentTime,Boolean throws)+3096    Facebook.FacebookSignedRequest.Parse(String secret,String signedRequestValue)+445    Facebook.FacebookSignedRequest.GetSignedRequest(String appSecret,HttpContextBase httpContext)+931    Facebook.FacebookSession.GetSession(String appId,String appSecret,HttpContextBase httpContext,FacebookSignedRequest signedRequest)+1031    Facebook.FacebookSession.GetSession(String appId,String appSecret,HttpContextBase httpContext)+128    Facebook.Web.FacebookWebContext.get_Session()+317    Facebook.Web.FacebookWebContext.IsAuthenticated()+ 136    Facebook.Web.FacebookWebContext.IsAuthorized(String [] permissions)+186    Facebook.Web.Mvc.CanvasAuthorizeAttribute.OnAuthorization(AuthorizationContext filterContext,IFacebookApplication settings)+572    Facebook.Web.Mvc.FacebookAuthorizeAttributeBase.OnAuthorization(AuthorizationContext filterContext)+182    System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext,IList 1 filters, ActionDescriptor actionDescriptor) +149 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +831 System.Web.Mvc.Controller.ExecuteCore() +136 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +233 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39 System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +68 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44 System.Web.Mvc.Async.<>c__DisplayClass8 1.b__7(IAsyncResult )+42    System.Web.Mvc.Async.WrappedAsyncResult`1.End()+ 142    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+54    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+40    System.Web.Mvc。&lt;&gt; c _DisplayClasse.b_ d()+61    System.Web.Mvc.SecurityUtil.b _0(动作f)+31    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)+56    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+110    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)+38    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+ 690    System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+199


版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.1我

1 个答案:

答案 0 :(得分:0)

试试这个:

[CanvasAuthorize(Permissions = "user_about_me")]
public ActionResult About()
{
    CanvasAuthorizer auth = new CanvasAuthorizer();
    FacebookWebClient client = new FacebookWebClient(auth.FacebookWebRequest.Session.AccessToken);

    dynamic result = client.Get("me");

    ViewData["Firstname"] = result.first_name;
    ViewData["Lastname"] = result.last_name;


    return View();
}