[在项目网址类型时显示登录索引

问题描述 投票:0回答:1

这可能是一个最简单的问题,但我面临以下问题。我有一个项目,并具有http://localhost/Some.Web/Login/Index的登录视图。如果输入http://localhost/Some.Web/,我想将其重定向到登录页面。目前,我收到“ 找不到资源。”错误消息。我的路线配置具有以下条目。

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Login", action = "Index", id = UrlParameter.Optional }
            );

我在做什么错。接受建议。

asp.net-mvc asp.net-mvc-5 asp.net-mvc-routing
1个回答
0
投票

有两种方法可以设置自定义路由,例如[routre("your route")]

设置时,请将其添加到您的路线中。

routes.MapMvcAttributeRoutes(); to the routeconfig.cs file

并且您的控制器中还有另一种方法来检查用户是否被授权重定向到该页面,否则将重定向到登录页面

if(userIsValid)
{
redirect("main page here")
}
else{

redirect("login page here")

}
© www.soinside.com 2019 - 2024. All rights reserved.