Skip to content
Permalink
Browse files

Add error handling around ExtractHandlerPathFromWebServerConfiguratio…

…nXml
  • Loading branch information...
mythz committed Oct 28, 2016
1 parent 18cfe57 commit 4bb1e35121a3de9f9959af6f613994ca2ee082a8
Showing with 17 additions and 9 deletions.
  1. +17 −9 src/ServiceStack/Platforms/PlatformNet.HostConfig.cs
@@ -136,7 +136,7 @@ private static void SetPathsFromConfiguration(HostConfig config, System.Configur
{
var webServerSection = webConfig.GetSection("system.webServer");
var rawXml = webServerSection?.SectionInformation.GetRawXml();
if (!String.IsNullOrEmpty(rawXml))
if (!string.IsNullOrEmpty(rawXml))
{
SetPaths(config, ExtractHandlerPathFromWebServerConfigurationXml(rawXml), locationPath);
}
@@ -156,11 +156,19 @@ private static void SetPathsFromConfiguration(HostConfig config, System.Configur

private static string ExtractHandlerPathFromWebServerConfigurationXml(string rawXml)
{
return XDocument.Parse(rawXml).Root.Element("handlers")
.Descendants("add")
.Where(handler => EnsureHandlerTypeAttribute(handler).StartsWith("ServiceStack"))
.Select(handler => handler.Attribute("path").Value)
.FirstOrDefault();
try
{
return XDocument.Parse(rawXml).Root.Element("handlers")
.Descendants("add")
.Where(handler => EnsureHandlerTypeAttribute(handler).StartsWith("ServiceStack"))
.Select(handler => handler.Attribute("path").Value)
.FirstOrDefault();
}
catch (Exception ex)
{
HostContext.AppHost?.OnStartupException(ex);
return null;
}
}

private static string EnsureHandlerTypeAttribute(XElement handler)
@@ -169,7 +177,7 @@ private static string EnsureHandlerTypeAttribute(XElement handler)
{
return handler.Attribute("type").Value;
}
return String.Empty;
return string.Empty;
}

private static void SetPaths(HostConfig config, string handlerPath, string locationPath)
@@ -178,11 +186,11 @@ private static void SetPaths(HostConfig config, string handlerPath, string locat

if (locationPath == null)
{
handlerPath = handlerPath.Replace("*", String.Empty);
handlerPath = handlerPath.Replace("*", string.Empty);
}

config.HandlerFactoryPath = locationPath ??
(String.IsNullOrEmpty(handlerPath) ? null : handlerPath);
(string.IsNullOrEmpty(handlerPath) ? null : handlerPath);

config.MetadataRedirectPath = "metadata";
}

0 comments on commit 4bb1e35

Please sign in to comment.
You can’t perform that action at this time.