Response.Redirect - Can anyone help me with this problem?

Dec 27, 2009 at 9:55 PM

Hi,

I can not redirect to another page of my IFrame / Canvas App
I need an example of how.

 Thanks in advance.
Carlos


This is my code:

 

 Public Sub Redirecciona(ByVal WebPage As Web.UI.Page, ByVal ToUrl As String, ByVal ApiKey As String, ByVal Secret As String)
        Dim ConnectSession As New Facebook.Session.ConnectSession(ApiKey, Secret)
        Dim Api As New Facebook.Rest.Api(ConnectSession)
        WebPage.Response.Redirect(String.Format("{0}?fb_sig_session_key=" + Api.Session.SessionKey + "&fb_sig_user=" + Api.Session.UserId.ToString(), ToUrl), True)
    End Sub

 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
........
........
........
........ 
Redirecciona(Me, "~/sw_misionenprogreso.aspx", SWApiKey, SWSecret)
End Sub

Public Sub Redirecciona(ByVal WebPage As Web.UI.Page, ByVal ToUrl As String, ByVal ApiKey As String, ByVal Secret As String)
        Dim ConnectSession As New Facebook.Session.ConnectSession(ApiKey, Secret)
        Dim Api As New Facebook.Rest.Api(ConnectSession)
        WebPage.Response.Redirect(String.Format("{0}?fb_sig_session_key=" + Api.Session.SessionKey + "&fb_sig_user=" + Api.Session.UserId.ToString(), ToUrl), True)
End Sub

 

This is the error:
 

Server Error in '/rkcradio' Application.

Value cannot be null.
Parameter name: String

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: String

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace: 

[ArgumentNullException: Value cannot be null.
Parameter name: String]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7469274
   System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt) +130
   Facebook.Session.CanvasSession.LoadFromRequest() +450
   Facebook.Session.CanvasSession..ctor(String appKey, String appSecret, List`1 permissions, Boolean readRequest) +121
   Facebook.Session.IFrameCanvasSession..ctor(String appKey, String appSecret) +18
   Facebook.Web.CanvasIFrameMasterPage..ctor() +31
   SpyWorld_MasterPage..ctor() +14
   ASP.spyworld_masterpage_master..ctor() +13
   __ASP.FastObjectFactory_app_web_spyworld_masterpage_master_cdcab7d2.Create_ASP_spyworld_masterpage_master() +20
   System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +249
   System.Web.UI.Page.get_Master() +51
   System.Web.UI.Page.ApplyMasterPage() +15
   System.Web.UI.Page.PerformPreInit() +45
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282



Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

 

 

 

 

Dec 30, 2009 at 1:46 PM

When you are writing an app in IFRAME, Facebook automatically attached several query string values

You can get list of query string by

Request.QueryString.ToString

And you will see something like this:

fb_sig_in_iframe=1&fb_sig_iframe_key=34173cb38f0234dbebc2ac2344228303f&fb_sig_locale=en_US&fb_sig_in_new_facebook=1&fb_sig_time=1262180617.0103&fb_sig_added=1&fb_sig_profile_update_time=1252977902&fb_sig_expires=1262268000&fb_sig_user=400020242322632&fb_sig_session_key=2.mGREcmy24D2325ffaKC9iN9WQ__.86400.1262268000-100000253152632&fb_sig_ss=Vin8amJyqfafeejtbTUOpg__&fb_sig_cookie_sig=c94c019a5c1fasaaa636e2e44b6364c5d&fb_sig_ext_perms=auto_publish_recent_activity&fb_sig_api_key=1e658fcd8c7c19233fjilja06a540413caa&fb_sig_app_id=27157513&fb_sig=da9ebfa8391m639e18d3dae834cc28


You can try to rebuild this string by calling API classes.  BUT, I just simply do this

Response.Redirect("someURL?" & Request.QueryString.ToString)

 

Dec 31, 2009 at 10:59 AM

Hello Syantien
Thanks for responding !!!

I tried your approach and got no more error !!!

but ... the page is redirected outside the canvas and go to the home page, :(
at some point the session is lost and restored again outside the canvas.

I am using MasterPage and Ajax. if I use the VS controls properties' "PostBackUrl or NavigateUrl" I have no problem to go to any page.

The problem only occurs when I need to go to another page in the code.

 

Jan 2, 2010 at 2:29 AM

Are you on IFRAME? or FBML?

What I mean was for IFrame,

IF you are on FBML, I ll double check to make sure your page has RequireLogin = True, to have proper values from Facebook.

Hope this helps.

Jan 2, 2010 at 9:52 AM

I'm in Iframe

 

Partial Class SpyWorld_MasterPage
    Inherits Facebook.Web.CanvasIFrameMasterPage 'System.Web.UI.MasterPage
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.RequireLogin = True
        FB_Conectado(SWApiKey, SWSecret)
    End Sub

I verify that .... in master page's Init


Partial Class RKC_MasterPage

    Inherits Facebook.Web.CanvasIFrameMasterPage

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        Me.RequireLogin = True

    End Sub

...

 

Mar 4, 2010 at 11:47 AM

reference http://facebooktoolkit.codeplex.com/Thread/View.aspx?ThreadId=85031

Mar 4, 2010 at 3:37 PM

Call RequireLogin at Page_PreRender

 

Mar 5, 2010 at 7:19 AM

I call it on OnInit, before base.OnInit, because CanvasSession.OnInit() is where all the checks of session stuff.  Also, you may want to make Facebook Api calls before PreRender().

Mar 23, 2010 at 8:46 PM
syantien wrote:

When you are writing an app in IFRAME, Facebook automatically attached several query string values

You can get list of query string by

Request.QueryString.ToString

And you will see something like this:

fb_sig_in_iframe=1&fb_sig_iframe_key=34173cb38f0234dbebc2ac2344228303f&fb_sig_locale=en_US&fb_sig_in_new_facebook=1&fb_sig_time=1262180617.0103&fb_sig_added=1&fb_sig_profile_update_time=1252977902&fb_sig_expires=1262268000&fb_sig_user=400020242322632&fb_sig_session_key=2.mGREcmy24D2325ffaKC9iN9WQ__.86400.1262268000-100000253152632&fb_sig_ss=Vin8amJyqfafeejtbTUOpg__&fb_sig_cookie_sig=c94c019a5c1fasaaa636e2e44b6364c5d&fb_sig_ext_perms=auto_publish_recent_activity&fb_sig_api_key=1e658fcd8c7c19233fjilja06a540413caa&fb_sig_app_id=27157513&fb_sig=da9ebfa8391m639e18d3dae834cc28


You can try to rebuild this string by calling API classes.  BUT, I just simply do this

Response.Redirect("someURL?" & Request.QueryString.ToString)

 

 Your suggestion of using Response.Redirect worked great.  Thank you for posting this suggestion.

LuoLong

Jun 29, 2010 at 7:02 PM
i got the same problem i found out that the fb_sig_expires=1262268000 ( the facebook expired time ) is 2 hour lower than my now server time i guest it normal since iam not on the same time zone as facebook server ( i guess ) ? i check the facebook canvasSession.cs source code private bool HaveValidCachedSession(CachedSessionInfo cachedSessionInfo, string authToken, string apiKeyRequestParam) ==> else if (DateTime.Now > cachedSessionInfo.ExpiryTime) there anyway to got the now server time of facebook, so we can compare time from the same source.