How do I use an Area
in ASP.NET Core?
I have an app that needs an Admin section. This section requires its Views to be placed in that area. All requests that start with Admin/
will need to be redirected to that area.
How do I use an Area
in ASP.NET Core?
I have an app that needs an Admin section. This section requires its Views to be placed in that area. All requests that start with Admin/
will need to be redirected to that area.
Areas Implementation in Routing First Create Area(Admin) using VS and add the following code into Startup.cs First Way to Implement:- Add Controller Login and Index Action and add Following Code, [Area(“Admin”)] is compulsory to add on controller level to perform asp.net areas Routing. Startup.cs
Note: Area routing must be placed first with non area routing, area: exists is compulsory to add area routing.
Controller Code:
This route may be called using http://localhost:111/Admin
Second Way to Implement Area Routing:- Add Following code into startup.cs.
Create an Area “Guest”, Add “GuestLogin” Controller and “Index” Action and add the following code into the newly created controller.
This route may be called using http://localhost:111/Guest
In the Microsoft docs to migrate from ASP.NET CORE 2.2 to 3.0 the suggestion is to:
I encountered some challenges while trying to fix my Area's while simultaneously having Identity to keep working - but the solution below seems to be working for ASP.NET CORE 3.0 :
Hopefully I could also help you out and reduce the research time :-)
Use this pattern in Configure method in Startup.Cs, as its full routing manner:
In Core 3.1 you should use below code in ConfigureServices method:
In ASP.NET Core 3.0. If you are working with Endpoint patterns, after adding the Area (Right click over project, Add, Area), you have to add manually routing pattern on startup.cs Configure method. (At this point the generated ScaffoldingReadMe.txt is out of date).
Scaffolding has generated all the files and added the required dependencies.
However the Application's Startup code may required additional changes for things to work end to end. Add the following code to the Configure method in your Application's Startup class if not already done:
it works for me.