Modify BuilderExtensions.UseMvc to not add any routes by default

Fixes #1879
This commit is contained in:
Pranav K 2015-01-23 12:50:21 -08:00
parent 5407ff3bd6
commit 071c697318
37 changed files with 105 additions and 42 deletions

View File

@ -2,12 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.IO;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Security; using Microsoft.AspNet.Security;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;

View File

@ -26,7 +26,12 @@ namespace TagHelperSample.Web
options.AddXmlDataContractSerializerFormatter(); options.AddXmlDataContractSerializerFormatter();
}); });
}); });
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -3,9 +3,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.WebApiCompatShim; using Microsoft.AspNet.Mvc.WebApiCompatShim;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Routing.Constraints;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Builder
{ {
public static class RouteBuilderExtensions public static class RouteBuilderExtensions
{ {

View File

@ -9,20 +9,31 @@ using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
/// <summary>
/// Extension methods for <see cref="IApplicationBuilder"/> to add Mvc to the request execution pipeline.
/// </summary>
public static class BuilderExtensions public static class BuilderExtensions
{ {
/// <summary>
/// Adds Mvc to the <see cref="IApplicationBuilder"/> request execution pipeline.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>The <paramref name="app"/>.</returns>
/// <remarks>This method only supports attribute routing. To add conventional routes use
/// <see cref="UseMvc(IApplicationBuilder, Action{IRouteBuilder})"/>.</remarks>
public static IApplicationBuilder UseMvc([NotNull] this IApplicationBuilder app) public static IApplicationBuilder UseMvc([NotNull] this IApplicationBuilder app)
{ {
return app.UseMvc(routes => return app.UseMvc(routes =>
{ {
// Action style actions
routes.MapRoute(null, "{controller}/{action}/{id?}", new { controller = "Home", action = "Index" });
// Rest style actions
routes.MapRoute(null, "{controller}/{id?}");
}); });
} }
/// <summary>
/// Adds Mvc to the <see cref="IApplicationBuilder"/> request execution pipeline.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="configureRoutes">A callback to configure Mvc routes.</param>
/// <returns>The <paramref name="app"/>.</returns>
public static IApplicationBuilder UseMvc( public static IApplicationBuilder UseMvc(
[NotNull] this IApplicationBuilder app, [NotNull] this IApplicationBuilder app,
[NotNull] Action<IRouteBuilder> configureRoutes) [NotNull] Action<IRouteBuilder> configureRoutes)

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace ActionConstraintsWebSite namespace ActionConstraintsWebSite

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace ActionResultsWebSite namespace ActionResultsWebSite

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace ActivatorWebSite namespace ActivatorWebSite

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
namespace AddServicesWebSite namespace AddServicesWebSite
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace AntiForgeryWebSite namespace AntiForgeryWebSite

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace ApiExplorerWebSite namespace ApiExplorerWebSite

View File

@ -17,7 +17,12 @@ namespace ApplicationModelWebSite
services.AddMvc(configuration); services.AddMvc(configuration);
}); });
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}");
});
} }
} }
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using Autofac; using Autofac;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Autofac; using Microsoft.Framework.DependencyInjection.Autofac;

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace BasicWebSite namespace BasicWebSite

View File

@ -25,7 +25,12 @@ namespace CompositeViewEngineWebSite
}); });
// Add MVC to the request pipeline // Add MVC to the request pipeline
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace ConnegWebSite namespace ConnegWebSite

View File

@ -4,8 +4,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
namespace CustomRouteWebSite namespace CustomRouteWebSite
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace CustomRouteWebSite namespace CustomRouteWebSite

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace FilesWebSite namespace FilesWebSite

View File

@ -50,7 +50,12 @@ namespace FiltersWebSite
app.UseMiddleware<AuthorizeBasicMiddleware>(); app.UseMiddleware<AuthorizeBasicMiddleware>();
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace FormatterWebSite namespace FormatterWebSite

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Routing.Constraints;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace LoggingWebSite namespace LoggingWebSite

View File

@ -37,7 +37,12 @@ namespace ModelBindingWebSite
app.UseErrorReporter(); app.UseErrorReporter();
// Add MVC to the request pipeline // Add MVC to the request pipeline
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace MvcTagHelpersWebSite namespace MvcTagHelpersWebSite

View File

@ -17,7 +17,12 @@ namespace PrecompilationWebSite
services.AddMvc(configuration); services.AddMvc(configuration);
}); });
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -36,7 +36,12 @@ namespace RazorInstrumentationWebSite
}); });
// Add MVC to the request pipeline // Add MVC to the request pipeline
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -1,13 +1,11 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.AspNet.Routing;
namespace RazorViewEngineOptionsWebsite namespace RazorViewEngineOptionsWebsite
{ {

View File

@ -31,7 +31,12 @@ namespace RazorWebSite
}); });
// Add MVC to the request pipeline // Add MVC to the request pipeline
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -22,7 +22,12 @@ namespace RequestServicesWebSite
// Initializes the RequestId service for each request // Initializes the RequestId service for each request
app.UseMiddleware<RequestIdMiddleware>(); app.UseMiddleware<RequestIdMiddleware>();
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -17,7 +17,12 @@ namespace ResponseCacheWebSite
services.AddMvc(configuration); services.AddMvc(configuration);
}); });
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace RoutingWebSite namespace RoutingWebSite

View File

@ -17,7 +17,12 @@ namespace TagHelpersWebSite
services.AddMvc(configuration); services.AddMvc(configuration);
}); });
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace UrlHelperWebSite namespace UrlHelperWebSite

View File

@ -25,7 +25,12 @@ namespace ValueProvidersWebSite
}); });
// Add MVC to the request pipeline // Add MVC to the request pipeline
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -19,7 +19,12 @@ namespace VersioningWebSite
services.AddScoped<TestResponseGenerator>(); services.AddScoped<TestResponseGenerator>();
}); });
app.UseMvc(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }

View File

@ -15,7 +15,13 @@ namespace ViewComponentWebSite
{ {
services.AddMvc(configuration); services.AddMvc(configuration);
}); });
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
} }
} }
} }