/// <summary> /// Initializes a new instance based on the specified <paramref name="context"/>. /// </summary> /// <param name="context">A HTTP context.</param> /// <param name="helper">A current SPA request helper.</param> public SpaRequestOptions(HttpContextBase context, SpaRequestHelper helper) { // Get a reference to the current request HttpRequestBase r = context.Request; // Get the host name from the query string appHost = r.QueryString["appHost"]; // Get the protocol from the query string appProtocol = r.QueryString["appProtocol"]; // Use the current URL as fallback for "appHost" and "appProtocol" HostName = string.IsNullOrWhiteSpace(appHost) ? r.Url?.Host : appHost; Protocol = string.IsNullOrWhiteSpace(appProtocol) ? r.Url?.Scheme : appProtocol; // Parse the "navLevels" and "navContext" parameters from the query string NavLevels = r.QueryString["navLevels"].ToInt32(1); NavContext = StringUtils.ParseBoolean(r.QueryString["navContext"]); // Parse the requests "parts" Parts = GetParts(r.QueryString["parts"]); // Get the URL and URI of the requested page Url = r.QueryString["url"]; Uri = new Uri($"{Protocol}://{HostName}{Url}"); // Parse the "siteId" and "pageId" parameters ("appSiteId" and "nodeId" are checked for legacy support) SiteId = Math.Max(r.QueryString["siteId"].ToInt32(-1), r.QueryString["appSiteId"].ToInt32(-1)); PageId = Math.Max(r.QueryString["pageId"].ToInt32(-1), r.QueryString["nodeId"].ToInt32(-1)); QueryString = r.QueryString; Culture = r.QueryString["culture"]; // Determine whether the current request is in debug mode if (helper.TryGetPreviewId(Url, out int previewId)) { PageId = previewId; IsPreview = true; } // Determine whether caching should be enabled EnableCaching = context.IsDebuggingEnabled == false && StringUtils.ParseBoolean(r.QueryString["cache"], true) && IsPreview == false; ShowHtmlErrors = context.IsDebuggingEnabled && context.IsCustomErrorEnabled == false && context.Request.Headers["Accept"].Contains("text/html"); }
/// <summary> /// Initializes a new instance based on the specified <paramref name="request"/>. /// </summary> /// <param name="request">A SPA request.</param> /// <param name="helper">A current SPA request helper.</param> public SpaRequestOptions(SpaRequest request, SpaRequestHelper helper) : this(request.HttpContext, helper) { }