c# - 将区域文件夹中的页面设置为asp.net core 2.2 MVC中的默认页面

标签 c# .net asp.net-mvc asp.net-core-mvc asp.net-core-2.2

我想将登录页面设置为默认页面。登录页面存在于区域文件夹中

下面是项目结构

enter image description here

我曾尝试在 Startup.cs 页面中设置默认路由,但无法设置 下面是 starup.cs 的快照

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

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

每次我收到错误 404 错误 无法找到确切的问题所在

Controller 代码:

    [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

最简单的方法是为areacontrolleraction配置默认值:

    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: "{area=Identity}/{controller=Account}/{action=Signin}"
        );
    });

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();
        }
    }

关于c# - 将区域文件夹中的页面设置为asp.net core 2.2 MVC中的默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56665257/

相关文章:

.net - 在 Windows 7 64 位和 Windows XP 32 位上创建 ClickOnce 应用程序 (mage.exe)

c# - 获取商店商品描述

c# - 将 GetWhere 查询 (Func<entityDTO,bool>) 传递给需要 (Func<entity,bool>) 参数才能工作的数据层方法

c# - 直接使用 LINQ 修改值?

c# - 使用 MVC5 允许来自不同域的帧

c# - 使用 ASP.Net 5 进行 JwtBearer 身份验证

c# - 如何从 Asp.net MVC 中的 ListBoxFor 选择框返回空列表而不是空列表?

c# - 如何以编程方式管理 SSIS 脚本组件输出列及其属性

c# - 我需要帮助在 C# 中使用 <string, char> 格式的字典

c# - 如何防止 WebClient 类自动跟随 header 中的位置?