2017-04-05 96 views
1

我希望這個網址「http://localhost:45678/」帶我去我的Login.cshtml有包含的AccountController設置登錄頁面,在asp.net mvc的默認頁5

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

這是我如何做到這一點的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 } 
     ); 
    } 

但是,它給了我一個 「服務器錯誤 '/' 應用。」 「沒有找到您要查的資源。」。什麼是正確的做法呢?

+2

'controller =「Account」'(not'「AccountController」') –

回答

4

你的控制器名稱是錯誤的。請致電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 } 
     ); 
    } 
+0

...我需要更多的咖啡。謝啦。我會接受你的答案,當我能 – user1166085

+0

@ user1166085沒問題=) – Valkyrie

0

試試這個

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

確保您在意見段登錄頁>帳戶

0

添加授權屬性到你需要的。 要記錄則u創建一個在您登錄邏輯重定向的所有控制器。