Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kamranayub/AttributeRouting
base: 9fd99cf0c0
...
head fork: kamranayub/AttributeRouting
compare: 9fba939f69
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 17 files changed
  • 0 commit comments
  • 3 contributors
Commits on Apr 11, 2012
@leoasis leoasis Added test and bugfix c67e0dc
Commits on Apr 12, 2012
@mccalltd mccalltd Merge pull request #59 from leoasis/default-areaurl-when-subdomain-by…
…-config

Bug with AreaUrl when Subdomains configured by configuration object and no Subdomain set in RouteAreaAttribute
b3e2807
@kamranayub Fix nuget tool path 907a936
@kamranayub Merging in master #59 eb2ac87
@kamranayub Add back framework-specific route attributes (HttpRoute and Route)
MVC accepts HttpVerbs overload and Web API accepts HttpMethod overload
9fba939
View
4 build.xml
@@ -53,8 +53,8 @@
TaskDirectory="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\" />
<MakeDir Directories="$(OutputDir)"/>
- <Exec Command="nuget pack %(MainNuspec.Identity) -Version $(Version) -OutputDirectory $(OutputDir)"/>
- <Exec Command="nuget pack %(SymbolsNuspec.Identity) -Version $(Version) -Symbols -OutputDirectory $(OutputDir)"/>
+ <Exec Command="src\.nuget\nuget pack %(MainNuspec.Identity) -Version $(Version) -OutputDirectory $(OutputDir)"/>
+ <Exec Command="src\.nuget\nuget pack %(SymbolsNuspec.Identity) -Version $(Version) -Symbols -OutputDirectory $(OutputDir)"/>
</Target>
<Target Name="NugetPush" DependsOnTargets="NugetPack">
View
3  src/AttributeRouting.Specs/Subjects/Http/StandardUsageController.cs
@@ -1,5 +1,4 @@
using System.Web.Http;
-using System.Web.Mvc;
using AttributeRouting.Web.Http;
namespace AttributeRouting.Specs.Subjects.Http
@@ -36,7 +35,7 @@ public string Wildcards()
return "";
}
- [Route("api/AnyVerb")]
+ [HttpRoute("api/AnyVerb")]
public string AnyVerb()
{
return "";
View
1  src/AttributeRouting.Specs/Subjects/StandardUsageController.cs
@@ -1,5 +1,4 @@
using System.Web.Mvc;
-using AttributeRouting.Web;
using AttributeRouting.Web.Mvc;
namespace AttributeRouting.Specs.Subjects
View
10 src/AttributeRouting.Specs/Subjects/SubdomainControllers.cs
@@ -14,6 +14,16 @@ public ActionResult Index()
}
}
+ [RouteArea("NoSubdomain")]
+ public class SubdomainControllerWithoutSubdomainInAttribute : Controller
+ {
+ [GET("")]
+ public ActionResult Index()
+ {
+ return Content("");
+ }
+ }
+
[RouteArea("Admin", Subdomain = "private", AreaUrl = "admin")]
public class SubdomainWithAreaUrlController : Controller
{
View
17 src/AttributeRouting.Specs/Tests/Subdomains/RouteReflectorTests.cs
@@ -53,5 +53,22 @@ public void Returns_subdomain_specified_for_area_via_configuration_object()
Assert.That(spec.AreaName, Is.EqualTo("Users"));
Assert.That(spec.AreaUrl, Is.EqualTo(null));
}
+
+ [Test]
+ public void Returns_null_area_url_when_controller_configured_with_subdomain_only_via_configuration_object()
+ {
+ var configuration = new AttributeRoutingConfiguration();
+ configuration.AddRoutesFromController<SubdomainControllerWithoutSubdomainInAttribute>();
+ configuration.MapArea("NoSubdomain").ToSubdomain("subdomain");
+
+ var reflector = new RouteReflector(configuration);
+ var specs = reflector.GenerateRouteSpecifications().ToList();
+
+ var spec = specs.SingleOrDefault();
+ Assert.That(spec, Is.Not.Null);
+ Assert.That(spec.Subdomain, Is.EqualTo("subdomain"));
+ Assert.That(spec.AreaName, Is.EqualTo("NoSubdomain"));
+ Assert.That(spec.AreaUrl, Is.EqualTo(null));
+ }
}
}
View
2  src/AttributeRouting.Web.Http.SelfHost/RestfulHttpMethodConstraint.cs
@@ -18,7 +18,7 @@ public RestfulHttpMethodConstraint(params HttpMethod[] allowedMethods)
}
- public ICollection<string> AllowedMethods
+ ICollection<string> IRestfulHttpMethodConstraint.AllowedMethods
{
get { return new ReadOnlyCollection<string>(base.AllowedMethods.Select(method => method.Method).ToList()); }
}
View
1  src/AttributeRouting.Web.Http/AttributeRouting.Web.Http.csproj
@@ -71,6 +71,7 @@
</Compile>
<Compile Include="DefaultHttpRouteConventionAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="HttpRouteAttribute.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AttributeRouting\AttributeRouting.csproj">
View
24 src/AttributeRouting.Web.Http/HttpRouteAttribute.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Linq;
+using System.Net.Http;
+
+namespace AttributeRouting.Web.Http
+{
+ /// <summary>
+ /// The route information for an action.
+ /// </summary>
+ public class HttpRouteAttribute : RouteAttributeBase
+ {
+ public HttpRouteAttribute(string routeUrl)
+ : base(routeUrl)
+ {
+
+ }
+
+ public HttpRouteAttribute(string routeUrl, params HttpMethod[] allowedMethods)
+ : base(routeUrl)
+ {
+ HttpMethods = allowedMethods.Select(m => m.Method).ToArray();
+ }
+ }
+}
View
1  src/AttributeRouting.Web.Mvc/AttributeRouting.Web.Mvc.csproj
@@ -52,6 +52,7 @@
<Compile Include="AttributeRoutingConfiguration.cs" />
<Compile Include="Framework\Factories\MvcAttributeRouteFactory.cs" />
<Compile Include="Framework\Factories\UrlParameterFactory.cs" />
+ <Compile Include="RouteAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RestfulRouteConventionAttribute.cs" />
<Compile Include="RouteCollectionExtensions.cs" />
View
24 src/AttributeRouting.Web.Mvc/RouteAttribute.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Linq;
+using System.Web.Mvc;
+using AttributeRouting.Helpers;
+
+namespace AttributeRouting.Web.Mvc
+{
+ /// <summary>
+ /// The route information for an action.
+ /// </summary>
+ public class RouteAttribute : RouteAttributeBase
+ {
+ public RouteAttribute(string routeUrl)
+ : base(routeUrl)
+ {
+ }
+
+ public RouteAttribute(string routeUrl, HttpVerbs allowedMethods)
+ : base(routeUrl)
+ {
+ HttpMethods = allowedMethods.ToString().ToUpper().SplitAndTrim(new[] {","});
+ }
+ }
+}
View
4 src/AttributeRouting/AttributeRouting.csproj
@@ -85,7 +85,7 @@
<Compile Include="Logging\LogWriter.cs" />
<Compile Include="POSTAttribute.cs" />
<Compile Include="PUTAttribute.cs" />
- <Compile Include="RouteAttribute.cs" />
+ <Compile Include="RouteAttributeBase.cs" />
<Compile Include="RouteConstraintAttributeBase.cs" />
<Compile Include="RouteConventionAttribute.cs" />
<Compile Include="RoutePrefixAttribute.cs" />
@@ -108,4 +108,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>
View
2  src/AttributeRouting/DELETEAttribute.cs
@@ -3,7 +3,7 @@ namespace AttributeRouting
/// <summary>
/// Defines a route for an action constrained to requests providing an httpMethod value of DELETE.
/// </summary>
- public class DELETEAttribute : RouteAttribute
+ public class DELETEAttribute : RouteAttributeBase
{
/// <summary>
/// Specify a route for an action constrained to requests providing an httpMethod value of DELETE.
View
12 src/AttributeRouting/Framework/RouteReflector.cs
@@ -53,12 +53,13 @@ private IEnumerable<RouteSpecification> GenerateRouteSpecifications(IEnumerable<
orderby controllerIndex, routeAttribute.Precedence
// precedence is within a controller
let routeName = routeAttribute.RouteName
+ let subdomain = GetAreaSubdomain(routeAreaAttribute)
select new RouteSpecification
{
AreaName = routeAreaAttribute.SafeGet(a => a.AreaName),
- AreaUrl = GetAreaUrl(routeAreaAttribute),
+ AreaUrl = GetAreaUrl(routeAreaAttribute, subdomain),
AreaUrlTranslationKey = routeAreaAttribute.SafeGet(a => a.TranslationKey),
- Subdomain = GetAreaSubdomain(routeAreaAttribute),
+ Subdomain = subdomain,
RoutePrefixUrl = GetRoutePrefix(routePrefixAttribute, actionMethod, convention),
RoutePrefixUrlTranslationKey = routePrefixAttribute.SafeGet(a => a.TranslationKey),
ControllerType = controllerType,
@@ -90,16 +91,17 @@ private IEnumerable<RouteSpecification> GenerateRouteSpecifications(IEnumerable<
return attributes.OrderBy(a => a.Order);
}
- private static string GetAreaUrl(RouteAreaAttribute routeAreaAttribute)
+ private static string GetAreaUrl(RouteAreaAttribute routeAreaAttribute, string subdomain)
{
if (routeAreaAttribute == null)
return null;
- // If a subdomain is specified for the area, then assume the area url is blank;
+ // If a subdomain is specified for the area either in the RouteAreaAttribute or via
+ // configuration, then assume the area url is blank;
// eg: admin.badass.com.
// However, our fearless coder can decide to explicitly specify an area url if desired;
// eg: internal.badass.com/admin.
- if (routeAreaAttribute.Subdomain.HasValue() && routeAreaAttribute.AreaUrl.HasNoValue())
+ if (subdomain.HasValue() && routeAreaAttribute.AreaUrl.HasNoValue())
return null;
return routeAreaAttribute.AreaUrl ?? routeAreaAttribute.AreaName;
View
2  src/AttributeRouting/GETAttribute.cs
@@ -3,7 +3,7 @@ namespace AttributeRouting
/// <summary>
/// Defines a route for an action constrained to requests providing an httpMethod value of GET.
/// </summary>
- public class GETAttribute : RouteAttribute
+ public class GETAttribute : RouteAttributeBase
{
/// <summary>
/// Specify a route for an action constrained to requests providing an httpMethod value of GET.
View
2  src/AttributeRouting/POSTAttribute.cs
@@ -3,7 +3,7 @@ namespace AttributeRouting
/// <summary>
/// Defines a route for an action constrained to requests providing an httpMethod value of POST.
/// </summary>
- public class POSTAttribute : RouteAttribute
+ public class POSTAttribute : RouteAttributeBase
{
/// <summary>
/// Specify a route for an action constrained to requests providing an httpMethod value of POST.
View
2  src/AttributeRouting/PUTAttribute.cs
@@ -3,7 +3,7 @@ namespace AttributeRouting
/// <summary>
/// Defines a route for an action constrained to requests providing an httpMethod value of PUT.
/// </summary>
- public class PUTAttribute : RouteAttribute
+ public class PUTAttribute : RouteAttributeBase
{
/// <summary>
/// Specify a route for an action constrained to requests providing an httpMethod value of PUT.
View
19 src/AttributeRouting/RouteAttribute.cs → src/AttributeRouting/RouteAttributeBase.cs
@@ -9,19 +9,28 @@ namespace AttributeRouting
/// The route information for an action.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
- public class RouteAttribute : Attribute, IRouteAttribute
+ public abstract class RouteAttributeBase : Attribute, IRouteAttribute
{
+ protected RouteAttributeBase(string routeUrl)
+ {
+ if (routeUrl == null) throw new ArgumentNullException("routeUrl");
+
+ RouteUrl = routeUrl;
+ Order = int.MaxValue;
+ Precedence = int.MaxValue;
+ }
+
/// <summary>
/// Specify the route information for an action.
/// </summary>
/// <param name="routeUrl">The url that is associated with this action</param>
/// <param name="allowedMethods">The httpMethods against which to constrain the route</param>
- public RouteAttribute(string routeUrl, params string[] allowedMethods)
+ protected RouteAttributeBase(string routeUrl, params string[] allowedMethods)
{
if (routeUrl == null) throw new ArgumentNullException("routeUrl");
- if (allowedMethods.Any(m => !Regex.IsMatch(m, "HEAD|GET|POST|PUT|DELETE")))
- throw new ArgumentException("The allowedMethods are restricted to either HEAD, GET, POST, PUT, or DELETE.", "allowedMethods");
+ if (HttpMethods.Any(m => !Regex.IsMatch(m, "HEAD|GET|POST|PUT|DELETE|PATCH|OPTIONS|TRACE")))
+ throw new InvalidOperationException("The allowedMethods are restricted to either HEAD, GET, POST, PUT, DELETE, PATCH, OPTIONS, or TRACE.");
RouteUrl = routeUrl;
HttpMethods = allowedMethods;
@@ -37,7 +46,7 @@ public RouteAttribute(string routeUrl, params string[] allowedMethods)
/// <summary>
/// The HttpMethods this route is constrained against.
/// </summary>
- public string[] HttpMethods { get; private set; }
+ public string[] HttpMethods { get; protected set; }
/// <summary>
/// The order of this route among all the routes defined against this action.

No commit comments for this range

Something went wrong with that request. Please try again.