-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
- The issue is related to Sitecore 9 application. App is hosted locally on IIS 10 with integrated v4.0 application pool. I did check with standard ASP.NET MVC app and it should work fine (details in 4.; similar deployment settings).
- Webpack configuration is done via sitecore's initialize pipeline. This is a substitute for Application_Start and works fine with all initializations that I have. Configuration code:
private void RegisterWebpack()
{
var applicationInstance = HttpContext.Current.ApplicationInstance;
applicationInstance.ConfigureWebpack(new WebpackConfig
{
AssetManifestPath = "~/webpack-assets.json",
AssetOutputPath = "~/",
});
}- Build succeeds, but when trying to enter website, application crashes with exception
[HttpException (0x80004005): Server operation is not available in this context.]
System.Web.HttpServerUtility.MapPath(String path) +225
Webpack.NET.Webpack.GetAssetDictionaryForConfig(WebpackConfig configuration, HttpServerUtilityBase httpServerUtility) +26
System.Linq.WhereSelectArrayIterator`2.MoveNext() +78
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +436
System.Linq.Enumerable.ToList(IEnumerable`1 source) +70
System.Lazy`1.CreateValue() +708
System.Lazy`1.LazyInitValue() +184
Webpack.NET.Webpack.GetAssetUrl(String assetName, String assetType, Boolean required) +101
Webpack.NET.UrlHelperExtensions.WebpackAsset(UrlHelper urlHelper, String assetName, String assetType, Boolean required) +87
ASP._Page_Views_Shared__Default_cshtml.Execute() in [full local path here]\Views\Shared\_Default.cshtml:17
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +148
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +122
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +136
Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +257
- I did some digging and found out that applicationInstance used in registration has Server property with null assigned to _context. This propagates into HttpServerUtility.MapPath and crashes as this method requires _context field to exist. In standard ASP.NET MVC app this _context is filled at Application_Start.
- When I move the code from initialize pipeline's handler directly to _Default.cshtml then everything works fine, because at this point HttpContext.Current.ApplicationInstance.Server contains _context with proper object assigned.
- I found out a suggestion (here) to use System.Web.Hosting.HostingEnvironment.MapPath method instead of HttpServerUtility.MapPath, because it does not require HttpContext and under the hood HttpServerUtility.MapPath reaches to suggested method.
Metadata
Metadata
Assignees
Labels
No labels