MVC4設定偽靜態---路由偽靜態

來源:互聯網
上載者:User

標籤:inf   public   reg   mvc   out   http   routes   cti   res   

有些客戶要求設定靜態,為了完成需求,而且更簡單的做法就是設定偽靜態,例如:http://localhost:80/Home/Index.html ,也可以訪問http://localhost:80/Home/Index 這是比較簡單省力的一個辦法,如果每個頁面都是產生一個靜態,訪問速度是提高了,可代碼量就增加,我們就可以利用mvc4的路由設定偽靜態。

        public static void RegisterRoutes(RouteCollection routes)        {            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                       routes.MapRoute(               "Action1Html", // action偽靜態                 "{controller}/{action}.html",// 帶有參數的 URL                 new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數預設值             );            routes.MapRoute(               "IDHtml", // id偽靜態                 "{controller}/{action}/{id}.html",// 帶有參數的 URL                 new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數預設值             );            routes.MapRoute(                "ActionHtml", // action偽靜態                  "{controller}/{action}.html/{id}",// 帶有參數的 URL                  new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數預設值              );            routes.MapRoute(                "ControllerHtml", // controller偽靜態                  "{controller}.html/{action}/{id}",// 帶有參數的 URL                  new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 參數預設值              );            routes.MapRoute(               "Root",               "",               new { controller = "Home", action = "Index", id = UrlParameter.Optional });//根目錄匹配              routes.MapRoute(               name: "Default",               url: "{controller}/{action}/{id}",               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//預設配置           );        }

 

MVC4設定偽靜態---路由偽靜態

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.