Ángel Ángel - 3 years ago 109
ASP.NET (C#) Question

Can not retrieve SharePoint context from web portal

We deployed and registered an APP in SharePoint Online. This application redirects to a web portal that we also published in an IIS with visibility from the Internet. This IIS has been configured with basic authentication.

In this scenario, the APP doesn't retrieve the SharePoint context. In the Page_PreInit method (defined in file "Default.aspx.cs"), when the execution reaches the line "switch (SharePointContextProvider.CheckRedirectionStatus (Context, out redirectUrl))", the next line to be executed is "case RedirectionStatus.CanNotRedirect : ".

We have also tried to deploy the web portal into an Azure site, but the result is the same.

How should we configure IIS authentication to be able to retrieve SharePoint context?

If we configured the authentication propertly, what might be wrong and how could we solve it?

Thank you for your replies!

Answer Source

Could you please share your code?

Generally this code should work under "Page_PreInit"

Uri redirectUrl;
            switch (SharePointContextProvider.CheckRedirectionStatus(Context, out redirectUrl))
                case RedirectionStatus.Ok:
                case RedirectionStatus.ShouldRedirect:
                    Response.Redirect(redirectUrl.AbsoluteUri, endResponse: true);
                case RedirectionStatus.CanNotRedirect:
                    Response.Write("An error occurred while processing your request.");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download