How to use an Area in ASP.NET Core

前端 未结 8 750
[愿得一人]
[愿得一人] 2020-11-28 23:45

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 request

8条回答
  •  心在旅途
    2020-11-29 00:15

    In the Microsoft docs to migrate from ASP.NET CORE 2.2 to 3.0 the suggestion is to:

    Replace UseMvc with UseEndpoints.

    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 :

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
        endpoints.MapControllerRoute("areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
    });
    

    Hopefully I could also help you out and reduce the research time :-)

提交回复
热议问题