简体   繁体   English

在asp.net mvc 5中将“登录”页面设置为默认页面

[英]Setting Login page as default page in asp.net mvc 5

i want this url " http://localhost:45678/ " to bring me to my Login.cshtml that has a AccountController that contains 我希望这个网址“ http:// localhost:45678 / ”将我带到我的Login.cshtml中,其中的AccountController包含

public ActionResult Login()
{
    return this.View();
}

This is how i do it in RoutesConfig.cs 这是我在RoutesConfig.cs中执行的操作

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapMvcAttributeRoutes();

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

However, it is giving me a "Server Error in '/' Application." 但是,它给了我一个“'/'应用程序中的服务器错误”。 "The resource cannot be found.". “没有找到您要查的资源。”。 what is the right way to do it? 正确的方法是什么?

Your controller name is wrong. 您的控制器名称错误。 instead calling AccountController , you need to call Account . 而不是调用AccountController ,您需要调用Account

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapMvcAttributeRoutes();

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

Try this 尝试这个

public ActionResult Login()
{
  return View();
}

Make sure you have login page in the views section > Account 确保您在视图部分>帐户中具有登录页面

在需要登录的所有控制器上添加授权属性。然后在登录逻辑中创建重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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