I'm not sure how much of a hack this is, but we got tired of the HostWebUrl; So we edited the SharePointContext.cs:
- On Home controller we save the
SPHostUrl if provided.
- Where SharePointContext.cs tries to resolve the host url from
HttpContext.Request.QueryString, if the
QueryString does not contain the
SPHostUrl we simply read it from the cookie.
Session is not easily available). All in all a few lines of code in one single place. And it works great between production and development.
public ActionResult Index()
var host = HttpContext.Request.QueryString["SPHostUrl"];
HttpContext.Response.AppendCookie(new HttpCookie("SPHostUrl", host));
public static Uri GetSPHostUrl(HttpRequestBase httpRequest)
var host = httpRequest.QueryString[SPHostUrlKey];
var cookie = httpRequest.Cookies.Get(SPHostUrlKey);
if (cookie != null) host = cookie.Value;
var spHostUrlString = TokenHelper.EnsureTrailingSlash(host);