简体   繁体   中英

Set Page from Area Folder as default page in asp.net core 2.2 MVC

I want to set Login Page as Default page.Login page is present in Area Folder

Below is the project structure

在此处输入图片说明

i had tried to set default route in Startup.cs page but unable to set below is the snapshot of starup.cs

 app.UseMvc(routes =>
    {
        routes.MapRoute(
              name: "default",
              template: "identity/{controller=Account}/{action=Signin}");

        routes.MapRoute(
              name: "areaRoute",
              template: "{area:exists}/{controller}/{action}"
            );
    });

Every time i get error 404 error not able to find where is the exact issue

Controller Code:

    [Area("Identity")]
    [Route("identity/[controller]")]
    public class AccountController : BaseController
    {
        private readonly UserManager<ApplicationUser> _userManager;
        private readonly SignInManager<ApplicationUser> _signInManager;


        public AccountController(
         UserManager<ApplicationUser> userManager,
         SignInManager<ApplicationUser> signInManager
         )
        {
            _userManager = userManager;
            _signInManager = signInManager;
        }


        // GET: /Account/SignIn 
        [Route("[action]")]
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> SignIn(string returnUrl = null)
        {                
            return View();
        }
    }

I want to set Login Page as Default page.Login page is present in Area Folder

The easiest way is to configure default values for area , controller and action :

app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "identity/{controller=Account}/{action=Signin}");

        
 

 
 
  
  
 
  routes.MapRoute(
              name: "areaRoute",
              template: "{area:exists}/{controller}/{action}"
            );
 

 
 
        routes.MapRoute(
            name: "areaRoute",
            template: ""
        );
    });

Controller code : Need to Remove Route parameter

    [Area("Identity")]        
    public class AccountController : BaseController
    {
        private readonly UserManager<ApplicationUser> _userManager;
        private readonly SignInManager<ApplicationUser> _signInManager;


        public AccountController(
         UserManager<ApplicationUser> userManager,
         SignInManager<ApplicationUser> signInManager
         )
        {
            _userManager = userManager;
            _signInManager = signInManager;
        }


        // GET: /Account/SignIn            
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> SignIn(string returnUrl = null)
        {                
            return View();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM