zoukankan      html  css  js  c++  java
  • MVC配置伪静态

    提出需求

    伪静态能提高搜索引擎收录,还不影响硬盘寿命,是一个不错的选择,但是会增加CPU和内存开销,由于时候也需要实现伪静态。

    web.config配置

      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>

    修改路由配置

                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}.html",
                    defaults: new { controller = "Home", action = "Index" }
                );

    参数传值

    home/index.html?page=1
    home/index/1.html  (这种写法无法自定义参数名称,只能使用路由里配置的参数名称)

    如果URL没有page=1会报错,屏蔽报错用以下方法

            public ActionResult Welcome(int? page)
            {
                ViewBag.Message = ""+page+"";
                return View();
            }

    或者直接给默认值

            public ActionResult Welcome(int page=1)
            {
                ViewBag.Message = ""+page+"";
                return View();
            }
  • 相关阅读:
    洛谷 [SDOI2015]约数个数和 解题报告
    multiset-count
    multiset-begin
    multiset-begin
    set-value_comp
    set-value_comp
    multiset-constructors
    multiset-constructors
    set-upper_bound
    set-upper_bound
  • 原文地址:https://www.cnblogs.com/shya/p/4417727.html
Copyright © 2011-2022 走看看