3

I've deployed a provider hosted app (hosted on Azure) in SharePoint Online.

In my solution I have an aspx page (with a button) and a Client Web Part to add the page in SP as an App Part.

All works fine but when I click on my button, doing a postback, I receive this error:

An error occurred while processing your request.

Debugging the solution, I see that on Page_PreInit, the function SharePointContextProvider.CheckRedirectionStatus(Context, out redirectUrl) returns RedirectionStatus.CanNotRedirect

But I don't understand why...

3 Answers 3

1

With the help of Microsoft I found that on PostBack the function GetContextTokenFromRequest(HttpRequestBase request) cannot find any value in request.Form neither in request.QueryString for "AppContext", "AppContextToken", "AccessToken", "SPAppToken"

We temporary solved this issue inserting an HiddenField and then inserting a value in the Page.Load:

SPAppToken.Value = HttpContext.Current.Request.Params["SPAppToken"];

But at the end we found that the problem was only on Internet Explorer (Firefox and Chrome works correctly). We definitively solved the issue inserting in the Trusted Sites of IE the URL where my Azure hosted app is deployed.

0

I have seen the RedirectionStatus.CanNotRedirect pop up when the app fails to set up the SharePoint client context correctly. This can happen when the query strings are not set properly (or at all).

Your app part requires some info, such as the SPHostUrl, that are passed to your app part from SharePoint via the query string. It looks something like this:

?SPHostUrl=http%3A%2F%2Fmy%2Dsp%2Dsite&SPHostTitle=My%20SP%20Site&SPAppWebUrl=""&SPLanguage=en%2DUS&SPClientTag=0&SPProductNumber=15%2E0%2E4569%2E1000&SenderId=ABCDEFG

Since you say it works fine until you click the button, my suspicion would be that these query parameters are not getting passed back to your app with the postback. Can you check if that is the case?

1
  • Hi @Pete, I check the iframe URL where the app part is displayed and still remain the same, with all the params you wrote me! In my button in effect I don't do a redirect but I do a simple postback: code<asp:LinkButton ID="btnSalva" runat="server" Text="Salva" OnClick="btnSalva_Click" />code
    – Elena
    Commented Feb 13, 2015 at 8:39
0

For me the issue only occurred on Windows 7 and IE11 (worked fine on Windows 10 + IE11). Solution was to add the Azure web site URL where the app was running in to Trusted Sites in IE on the Windows 7 machines, and it started passing SPAppToken properly also on the redirect when pressing a button.

I was using UpdatePanel, however the issue occurred also when removing the UpdatePanel. This solution fixed it in both cases.

More elaborate discussion on the topic here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.