Answered by:
Querying AppWeb (remote web) URL from MVC controller in SharePoint Provider Hosted Add-In

Question
-
Answers
-
Hi,
If you want to get the app web Url, the following code for your reference.
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); var appwebUrl=spContext.SPAppWebUrl;
If you want to get the current site URL, the following code for your reference.
var currentWebUrl = string.Format("{0}://{1}{2}{3}", System.Web.HttpContext.Current.Request.Url.Scheme, System.Web.HttpContext.Current.Request.Url.Host, System.Web.HttpContext.Current.Request.Url.Port == 80 ? string.Empty : ":" + System.Web.HttpContext.Current.Request.Url.Port, System.Web.HttpContext.Current.Request.ApplicationPath);
Best Regards,
Dennis
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.- Marked as answer by pointtoshare Friday, October 19, 2018 10:30 AM
All replies
-
Hi,
If you want to get the app web Url, the following code for your reference.
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); var appwebUrl=spContext.SPAppWebUrl;
If you want to get the current site URL, the following code for your reference.
var currentWebUrl = string.Format("{0}://{1}{2}{3}", System.Web.HttpContext.Current.Request.Url.Scheme, System.Web.HttpContext.Current.Request.Url.Host, System.Web.HttpContext.Current.Request.Url.Port == 80 ? string.Empty : ":" + System.Web.HttpContext.Current.Request.Url.Port, System.Web.HttpContext.Current.Request.ApplicationPath);
Best Regards,
Dennis
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.- Marked as answer by pointtoshare Friday, October 19, 2018 10:30 AM
-
-
Hi,
Can you provide an example for the " app domain url"?
It is not mean "SPAppWebUrl"?
Did you try to use the "currentWebUrl" in code above?
Best Regards,
Dennis
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams. -