private static RequestContext RequestContextFactory(IComponentContext context) { var httpContextAccessor = context.Resolve <IHttpContextAccessor>(); var httpContext = httpContextAccessor.Current(); if (httpContext != null) { var mvcHandler = httpContext.Handler as MvcHandler; if (mvcHandler != null) { return(mvcHandler.RequestContext); } var hasRequestContext = httpContext.Handler as IHasRequestContext; if (hasRequestContext != null) { if (hasRequestContext.RequestContext != null) { return(hasRequestContext.RequestContext); } } } else { httpContext = new HttpContextPlaceholder(); } return(new RequestContext(httpContext, new RouteData())); }
private static HttpContextBase HttpContextBaseFactory(IComponentContext context) { if (IsRequestValid()) { return new HttpContextWrapper(HttpContext.Current); } var baseUrl = new Func<string>(() => string.Empty); var httpContextBase = new HttpContextPlaceholder(baseUrl); context.Resolve<IWebWorkContextAccessor>().CreateWorkContextScope(httpContextBase); return httpContextBase; }
private static HttpContextBase HttpContextBaseFactory(IComponentContext context) { if (IsRequestValid()) { return(new HttpContextWrapper(HttpContext.Current)); } var baseUrl = new Func <string>(() => string.Empty); var httpContextBase = new HttpContextPlaceholder(baseUrl); context.Resolve <IWebWorkContextAccessor>().CreateWorkContextScope(httpContextBase); return(httpContextBase); }
static HttpContextBase HttpContextBaseFactory(IComponentContext context) { if (IsRequestValid()) { return new HttpContextWrapper(HttpContext.Current); } var siteService = context.Resolve<ISiteService>(); // Wrapping the code accessing the SiteSettings in a function that will be executed later (in HttpContextPlaceholder), // so that the RequestContext will have been established when the time comes to actually load the site settings, // which requires activating the Site content item, which in turn requires a UrlHelper, which in turn requires a RequestContext, // thus preventing a StackOverflowException. var baseUrl = new Func<string>(() => siteService.GetSiteSettings().BaseUrl); var httpContextBase = new HttpContextPlaceholder(baseUrl); context.Resolve<IWorkContextAccessor>().CreateWorkContextScope(httpContextBase); return httpContextBase; }
static HttpContextBase HttpContextBaseFactory(IComponentContext context) { if (IsRequestValid()) { return(new HttpContextWrapper(HttpContext.Current)); } var siteService = context.Resolve <ISiteService>(); // Wrapping the code accessing the SiteSettings in a function that will be executed later (in HttpContextPlaceholder), // so that the RequestContext will have been established when the time comes to actually load the site settings, // which requires activating the Site content item, which in turn requires a UrlHelper, which in turn requires a RequestContext, // thus preventing a StackOverflowException. var baseUrl = new Func <string>(() => siteService.GetSiteSettings().BaseUrl); var httpContextBase = new HttpContextPlaceholder(baseUrl); return(httpContextBase); }
static HttpContextBase HttpContextBaseFactory(IComponentContext context) { var httpContext = context.Resolve<IHttpContextAccessor>().Current(); if (httpContext != null) return httpContext; var siteService = context.Resolve<ISiteService>(); // Wrapping the code accessing the SiteSettings in a function that will be executed later (in HttpContextPlaceholder), // so that the RequestContext will have been established when the time comes to actually load the site settings, // which requires activating the Site content item, which in turn requires a UrlHelper, which in turn requires a RequestContext, // thus preventing a StackOverflowException. var baseUrl = new Func<string>(() => siteService.GetSiteSettings().BaseUrl ?? "http://localhost" /* When Setup is running from the command line, no BaseUrl exists yet. */); var httpContextBase = new HttpContextPlaceholder(baseUrl); return httpContextBase; }
static RequestContext RequestContextFactory(IComponentContext context) { var httpContextAccessor = context.Resolve<IHttpContextAccessor>(); var httpContext = httpContextAccessor.Current(); if (httpContext != null) { var mvcHandler = httpContext.Handler as MvcHandler; if (mvcHandler != null) { return mvcHandler.RequestContext; } var hasRequestContext = httpContext.Handler as IHasRequestContext; if (hasRequestContext != null) { if (hasRequestContext.RequestContext != null) return hasRequestContext.RequestContext; } } else { httpContext = new HttpContextPlaceholder(); } return new RequestContext(httpContext, new RouteData()); }
static HttpContextBase HttpContextBaseFactory(IComponentContext context) { var httpContext = context.Resolve <IHttpContextAccessor>().Current(); if (httpContext != null) { return(httpContext); } var siteService = context.Resolve <ISiteService>(); // Wrapping the code accessing the SiteSettings in a function that will be executed later (in HttpContextPlaceholder), // so that the RequestContext will have been established when the time comes to actually load the site settings, // which requires activating the Site content item, which in turn requires a UrlHelper, which in turn requires a RequestContext, // thus preventing a StackOverflowException. var baseUrl = new Func <string>(() => siteService.GetSiteSettings().BaseUrl ?? "http://localhost" /* When Setup is running from the command line, no BaseUrl exists yet. */); var httpContextBase = new HttpContextPlaceholder(baseUrl); return(httpContextBase); }