diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs index 6f109d4a..9b54dab0 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapBuilder.cs @@ -407,7 +407,6 @@ protected virtual ISiteMapNode GetSiteMapNodeFromMvcSiteMapNodeAttribute(ISiteMa // Determine controller and (index) action string controller = type.Name.Substring(0, type.Name.IndexOf("Controller")); string action = (methodInfo != null ? methodInfo.Name : null) ?? "Index"; - string httpMethod = "*"; if (methodInfo != null) { // handle ActionNameAttribute @@ -416,15 +415,10 @@ protected virtual ISiteMapNode GetSiteMapNodeFromMvcSiteMapNodeAttribute(ISiteMa { action = actionNameAttribute.Name; } - - // handle AcceptVerbsAttribute - var acceptVerbsAttribute = methodInfo.GetCustomAttributes(typeof(AcceptVerbsAttribute), true).FirstOrDefault() as AcceptVerbsAttribute; - if (acceptVerbsAttribute != null) - { - httpMethod = string.Join(",", acceptVerbsAttribute.Verbs.ToArray()); - } } + string httpMethod = String.IsNullOrEmpty(attribute.HttpMethod) ? HttpVerbs.Get.ToString().ToUpperInvariant() : attribute.HttpMethod.ToUpperInvariant(); + // Handle title and description var title = attribute.Title; var description = String.IsNullOrEmpty(attribute.Description) ? title : attribute.Description; diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapNodeProvider.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapNodeProvider.cs index cc7651bc..de07ba03 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapNodeProvider.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/ReflectionSiteMapNodeProvider.cs @@ -200,7 +200,7 @@ protected virtual ISiteMapNodeToParentRelation GetSiteMapNodeFromMvcSiteMapNodeA // Determine controller and (index) action string controller = type.Name.Substring(0, type.Name.IndexOf("Controller")); string action = (methodInfo != null ? methodInfo.Name : null) ?? "Index"; - string httpMethod = "*"; + if (methodInfo != null) { // handle ActionNameAttribute @@ -209,15 +209,10 @@ protected virtual ISiteMapNodeToParentRelation GetSiteMapNodeFromMvcSiteMapNodeA { action = actionNameAttribute.Name; } - - // handle AcceptVerbsAttribute - var acceptVerbsAttribute = methodInfo.GetCustomAttributes(typeof(AcceptVerbsAttribute), true).FirstOrDefault() as AcceptVerbsAttribute; - if (acceptVerbsAttribute != null) - { - httpMethod = string.Join(",", acceptVerbsAttribute.Verbs.ToArray()); - } } + string httpMethod = String.IsNullOrEmpty(attribute.HttpMethod) ? HttpVerbs.Get.ToString().ToUpperInvariant() : attribute.HttpMethod.ToUpperInvariant(); + // Handle title and description var title = attribute.Title; var description = String.IsNullOrEmpty(attribute.Description) ? title : attribute.Description; diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapBuilder.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapBuilder.cs index 65449296..f434b907 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapBuilder.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Web.Mvc; using System.Xml.Linq; using MvcSiteMapProvider.Xml; using MvcSiteMapProvider.Collections.Specialized; @@ -114,17 +115,21 @@ protected virtual ISiteMapNode GetSiteMapNodeFromXmlElement(ISiteMap siteMap, XE //// Get area, controller and action from node declaration string area = node.GetAttributeValue("area"); string controller = node.GetAttributeValue("controller"); + string httpMethod = node.GetAttributeValueOrFallback("httpMethod", HttpVerbs.Get.ToString()).ToUpperInvariant(); + // Handle title and description + var title = node.GetAttributeValue("title"); + var description = String.IsNullOrEmpty(node.GetAttributeValue("description")) ? title : node.GetAttributeValue("description"); // Generate key for node string key = nodeKeyGenerator.GenerateKey( parentNode == null ? "" : parentNode.Key, node.GetAttributeValue("key"), node.GetAttributeValue("url"), - node.GetAttributeValue("title"), + title, area, controller, node.GetAttributeValue("action"), - node.GetAttributeValueOrFallback("httpMethod", "*").ToUpperInvariant(), + httpMethod, !(node.GetAttributeValue("clickable") == "false")); // Handle implicit resources @@ -133,9 +138,7 @@ protected virtual ISiteMapNode GetSiteMapNodeFromXmlElement(ISiteMap siteMap, XE // Create node ISiteMapNode siteMapNode = siteMapNodeFactory.Create(siteMap, key, implicitResourceKey); - // Handle title and description - var title = node.GetAttributeValue("title"); - var description = String.IsNullOrEmpty(node.GetAttributeValue("description")) ? title : node.GetAttributeValue("description"); + // Assign defaults siteMapNode.Title = title; @@ -147,7 +150,7 @@ protected virtual ISiteMapNode GetSiteMapNodeFromXmlElement(ISiteMap siteMap, XE siteMapNode.DynamicNodeProvider = node.GetAttributeValue("dynamicNodeProvider"); siteMapNode.ImageUrl = node.GetAttributeValue("imageUrl"); siteMapNode.TargetFrame = node.GetAttributeValue("targetFrame"); - siteMapNode.HttpMethod = node.GetAttributeValueOrFallback("httpMethod", "*").ToUpperInvariant(); + siteMapNode.HttpMethod = httpMethod; siteMapNode.Url = node.GetAttributeValue("url"); siteMapNode.CacheResolvedUrl = bool.Parse(node.GetAttributeValueOrFallback("cacheResolvedUrl", "true")); siteMapNode.CanonicalUrl = node.GetAttributeValue("canonicalUrl"); diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapNodeProvider.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapNodeProvider.cs index 84c82ce1..3b4115c0 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapNodeProvider.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/XmlSiteMapNodeProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Web.Mvc; using System.Xml.Linq; using MvcSiteMapProvider.Xml; using MvcSiteMapProvider.Collections.Specialized; @@ -188,17 +189,21 @@ protected virtual ISiteMapNodeToParentRelation GetSiteMapNodeFromXmlElement(XEle string area = node.GetAttributeValue("area"); string controller = node.GetAttributeValue("controller"); var parentKey = parentNode == null ? "" : parentNode.Key; + var httpMethod = node.GetAttributeValueOrFallback("httpMethod", HttpVerbs.Get.ToString()).ToUpperInvariant(); + // Handle title and description + var title = node.GetAttributeValue("title"); + var description = String.IsNullOrEmpty(node.GetAttributeValue("description")) ? title : node.GetAttributeValue("description"); // Generate key for node string key = helper.CreateNodeKey( parentKey, node.GetAttributeValue("key"), node.GetAttributeValue("url"), - node.GetAttributeValue("title"), + title, area, controller, node.GetAttributeValue("action"), - node.GetAttributeValueOrFallback("httpMethod", "*").ToUpperInvariant(), + httpMethod, !(node.GetAttributeValue("clickable") == "false")); // Handle implicit resources @@ -208,10 +213,6 @@ protected virtual ISiteMapNodeToParentRelation GetSiteMapNodeFromXmlElement(XEle var nodeParentMap = helper.CreateNode(key, parentKey, SourceName, implicitResourceKey); var siteMapNode = nodeParentMap.Node; - // Handle title and description - var title = node.GetAttributeValue("title"); - var description = String.IsNullOrEmpty(node.GetAttributeValue("description")) ? title : node.GetAttributeValue("description"); - // Assign defaults siteMapNode.Title = title; siteMapNode.Description = description; @@ -222,7 +223,7 @@ protected virtual ISiteMapNodeToParentRelation GetSiteMapNodeFromXmlElement(XEle siteMapNode.DynamicNodeProvider = node.GetAttributeValue("dynamicNodeProvider"); siteMapNode.ImageUrl = node.GetAttributeValue("imageUrl"); siteMapNode.TargetFrame = node.GetAttributeValue("targetFrame"); - siteMapNode.HttpMethod = node.GetAttributeValueOrFallback("httpMethod", "*").ToUpperInvariant(); + siteMapNode.HttpMethod = httpMethod; siteMapNode.Url = node.GetAttributeValue("url"); siteMapNode.CacheResolvedUrl = bool.Parse(node.GetAttributeValueOrFallback("cacheResolvedUrl", "true")); siteMapNode.CanonicalUrl = node.GetAttributeValue("canonicalUrl"); diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/DynamicNode.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/DynamicNode.cs index 810ba971..f886faae 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/DynamicNode.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/DynamicNode.cs @@ -159,6 +159,14 @@ public UpdatePriority UpdatePriority /// The sort order. public int? Order { get; set; } + /// + /// Gets or sets the HTTP method (such as GET, POST, or HEAD). + /// + /// + /// The HTTP method. + /// + public string HttpMethod { get; set; } + /// /// Copies the values for matching properties on an instance, but /// doesn't overwrite any values that are not set in this instance. @@ -236,6 +244,8 @@ public void SafeCopyTo(ISiteMapNode node) } if (this.Order != null) node.Order = (int)this.Order; + if (!string.IsNullOrEmpty(this.HttpMethod)) + node.HttpMethod = this.HttpMethod; } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/IMvcSiteMapNodeAttribute.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/IMvcSiteMapNodeAttribute.cs index 2eb98ef3..24b64cbd 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/IMvcSiteMapNodeAttribute.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/IMvcSiteMapNodeAttribute.cs @@ -155,5 +155,14 @@ public interface IMvcSiteMapNodeAttribute /// /// The SiteMap cache key. string SiteMapCacheKey { get; set; } + + /// + /// Gets or sets the HTTP method (such as GET, POST, or HEAD) to use to determine + /// node accessibility. + /// + /// + /// The HTTP method. + /// + string HttpMethod { get; set; } } } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/MvcSiteMapNodeAttribute.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/MvcSiteMapNodeAttribute.cs index ebdc1b14..b07343f3 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/MvcSiteMapNodeAttribute.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/MvcSiteMapNodeAttribute.cs @@ -166,5 +166,14 @@ public MvcSiteMapNodeAttribute() /// Gets or sets the name of the cache key this node is associated with /// public string SiteMapCacheKey { get; set; } + + /// + /// Gets or sets the HTTP method (such as GET, POST, or HEAD) to use to determine + /// node accessibility. + /// + /// + /// The HTTP method. + /// + public string HttpMethod { get; set; } } } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs index 4e21ac16..0604a980 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Web; +using System.Web.Mvc; using System.Web.Routing; using MvcSiteMapProvider.Globalization; using MvcSiteMapProvider.Web; @@ -75,6 +76,7 @@ IUrlPath urlPath protected readonly ISiteMap siteMap; protected readonly string key; protected readonly bool isDynamic; + protected string httpMethod = HttpVerbs.Get.ToString().ToUpperInvariant(); protected string title = String.Empty; protected string description = String.Empty; protected string imageUrl = String.Empty; @@ -114,12 +116,17 @@ public override ISiteMap SiteMap } /// - /// Gets or sets the HTTP method. + /// Gets or sets the HTTP method (such as GET, POST, or HEAD) to use to determine + /// node accessibility. /// /// /// The HTTP method. /// - public override string HttpMethod { get; set; } + public override string HttpMethod + { + get { return this.httpMethod; } + set { this.httpMethod = value; } + } /// /// Gets the implicit resource key (optional). diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs index 8083863d..ad6a3004 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs @@ -30,13 +30,6 @@ public virtual RequestContext CreateRequestContext(ISiteMapNode node, RouteData { var httpContext = this.CreateHttpContext(node); return new RequestContext(httpContext, routeData); - - //if (httpContext.Handler is MvcHandler) - // return ((MvcHandler)httpContext.Handler).RequestContext; - //else if (httpContext.Handler is Page) // Fixes #15 for interop with ASP.NET Webforms - // return new RequestContext(httpContext, ((Page)HttpContext.Current.Handler).RouteData); - //else - // return new RequestContext(httpContext, routeData); } public virtual RequestContext CreateRequestContext() diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/SiteMapHttpRequest.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/SiteMapHttpRequest.cs index 2b6d3852..cabc3113 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/SiteMapHttpRequest.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/SiteMapHttpRequest.cs @@ -1,5 +1,6 @@ using System; using System.Web; +using System.Web.Mvc; namespace MvcSiteMapProvider.Web.Mvc { @@ -62,13 +63,16 @@ public override string HttpMethod { get { - const StringComparison comparison = StringComparison.OrdinalIgnoreCase; - bool replaceMethod = this.node != null && - !String.IsNullOrEmpty(this.node.HttpMethod) && - !String.Equals(this.node.HttpMethod, "*", comparison); - return replaceMethod - ? this.node.HttpMethod.Split(',')[0] - : base.HttpMethod; + bool useRequest = this.node == null || + String.Equals(this.node.HttpMethod, "*") || + String.Equals(this.node.HttpMethod, "request", StringComparison.InvariantCultureIgnoreCase); + if (!useRequest) + { + return String.IsNullOrEmpty(this.node.HttpMethod) + ? HttpVerbs.Get.ToString().ToUpperInvariant() + : this.node.HttpMethod.ToUpperInvariant(); + } + return base.HttpMethod; } } }