Skip to content

Commit

Permalink
Remove all non-alphanumeric characters from the hostId. Fixes ##1006
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmelsayed committed Jan 4, 2017
1 parent 4643851 commit dea1a55
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.WebHost.WebHooks;
Expand Down Expand Up @@ -151,8 +152,17 @@ private static ScriptHostConfiguration CreateScriptHostConfiguration(WebHostSett

// If running on Azure Web App, derive the host ID from the default subdomain
// Otherwise, derive it from machine name and folder name
string hostId = _settingsManager.AzureWebsiteDefaultSubdomain
?? $"{Environment.MachineName}-{Path.GetFileName(Environment.CurrentDirectory)}";
string hostId = _settingsManager.AzureWebsiteDefaultSubdomain;
if (string.IsNullOrEmpty(hostId))
{
var sanitizedPath = Path.GetFileName(Environment.CurrentDirectory)
.Where(char.IsLetterOrDigit)
.Aggregate(new StringBuilder(), (b, c) => b.Append(c))
.ToString();

hostId = $"{Environment.MachineName}-{sanitizedPath}";
}

if (!String.IsNullOrEmpty(hostId))
{
// Truncate to the max host name length if needed
Expand Down

0 comments on commit dea1a55

Please sign in to comment.