protected SPAlternateUrl GetCurrentAlternateUrl(SPWebApplication webApp, AlternateUrlDefinition definition)
        {
            var alternateUrls = webApp.AlternateUrls;

            var url = definition.Url;
            var urlZone = (SPUrlZone)Enum.Parse(typeof(SPUrlZone), definition.UrlZone);

            return alternateUrls.GetResponseUrl(urlZone);
        }
        private void DeployDefinition(object modelHost, SPWebApplication webApp, AlternateUrlDefinition definition)
        {
            var alternateUrls = webApp.AlternateUrls;

            var url = definition.Url;
            var urlZone = (SPUrlZone)Enum.Parse(typeof(SPUrlZone), definition.UrlZone);

            var responseUrl = GetCurrentAlternateUrl(webApp, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = responseUrl,
                ObjectType = typeof(SPAlternateUrl),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (!string.IsNullOrEmpty(url))
            {
                responseUrl = new SPAlternateUrl(url, urlZone);
                alternateUrls.SetResponseUrl(responseUrl);
            }
            else
            {
                alternateUrls.UnsetResponseUrl(urlZone);
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = responseUrl,
                ObjectType = typeof(SPAlternateUrl),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            alternateUrls.Update();
        }
 public static ModelNode AddAlternateUrl(this ModelNode model, AlternateUrlDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
 public static ModelNode AddAlternateUrl(this ModelNode model, AlternateUrlDefinition definition)
 {
     return AddAlternateUrl(model, definition, null);
 }