我要将登录页面设置为默认页面。登录页面位于区域文件夹中
下面是项目结构
我曾尝试在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错误 找不到确切的问题在哪里
控制器代码:
[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();
}
}
答案 0 :(得分:1)
我要将登录页面设置为默认页面。登录页面位于区域文件夹中
最简单的方法是为area
,controller
和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: "{area=Identity}/{controller=Account}/{action=Signin}" ); });
控制器代码:需要删除Route参数
[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();
}
}