Skip to content

Instantly share code, notes, and snippets.

@pbjorklund
Created November 27, 2014 15:08
Show Gist options
  • Save pbjorklund/822cc9f4cb2b75b741a5 to your computer and use it in GitHub Desktop.
Save pbjorklund/822cc9f4cb2b75b741a5 to your computer and use it in GitHub Desktop.
var qsKeys = Request.QueryString.AllKeys;
if (qsKeys.Contains("SPAppWebUrl"))
{
AppWebUrl.Value = Request.QueryString["SPAppWebUrl"];
}
else
{
var rootUri = new UriBuilder(String.Concat(new Uri(Request.QueryString["SPHostUrl"]).Authority, "/sites/apps"))
{
Scheme = Uri.UriSchemeHttps,
Port = 443
};
SharePointOnlineHelper.RunInNewAppOnlyContext(rootUri.ToString(), appCtx =>
{
var web = appCtx.Web;
var appInstances = web.GetAppInstances();
var target = appCtx.LoadQuery(appInstances.Where(a => a.Title == "Site Konfigurator"));
appCtx.ExecuteQuery();
AppWebUrl.Value = target.Single().AppWebFullUrl;
});
}
@pbjorklund
Copy link
Author

And then pick it up via a asp hiddenfield

<asp:HiddenField ID="AppWebUrl" ClientIDMode="Static" runat="server" />
var appweburl = $('#AppWebUrl').val();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment