Using scopes in ASP.NET 5

I have an ASP.NET vNext (5) project. I am trying to add two areas to the project. My question is: how do I register areas in vNext? The System.Web.Mvc has disappeared, and an AreaRegistrationContext has been specified in it. I started searching in the MVC source code on GitHub. I found the Area attribute. However, I am not sure how to use it now.

Can someone explain to me (or provide a link) about how to use scopes in ASP.NET vNext?

Thanks!

+7
asp.net-mvc
source share
1 answer

In vNext, you register and configure the services that you intend to use in Startup.cs. Regional routes are added as regular routes. There is a sample here: https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Startup.cs

You can add an MVC route for such an area:

 app.UseMvc(routes => { routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action}"); }); 

Or you can use the route attribute as follows: [Route("[area]/Home")]

The [Area] attribute adorns controllers included in an area. It takes only one parameter, the name of the area. Here is an example: https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Areas/Travel/Controllers/HomeController.cs

 [Area("Travel")] public class HomeController : Controller { //... } 
+5
source share

All Articles