zoukankan      html  css  js  c++  java
  • MVC4.0 如何设置默认静态首页index.shtml

    1.不启用二级域名情况下(www.xxx.com)下设置默认静态首页index.shtml

      通过配置IIS的默认文档,设置默认首页地址

      

      然后在MVC的路由中写入忽略默认路由代码

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.IgnoreRoute("");
    
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "XXX.WebUI.Controllers" }//解决Controllers与Areas中控制器不能同名问题
        );
    

     2.启用二级域名情况下(xxx.xxx.com)下设置默认静态首页index.shtml

      实现接口IRouteConstraint接口

        public class DomainXXXXConstraint : IRouteConstraint
        {
            public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
            {
                return httpContext.Request.Url.Host.ToLowerInvariant() == "XXXX";
            }
        }
    

      然后在MVC的路由中写入忽略默认路由代码

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.IgnoreRoute("", new { DomainConstraint = new DomainXXXXConstraint() })
    
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new string[] { "XXX.WebUI.Controllers" }//解决Controllers与Areas中控制器不能同名问题
            );
        }
    
  • 相关阅读:
    CRMEB FormBuilder
    CRMEB 异常
    Layui select
    VS 发布报错 NETSDK1152: 找到了多个具有相同相对路径的发布输出文件
    Layui 文档 官网镜像
    datetimepicker 日期显示 年视图 月视图
    SpringBoot
    RabbitMQ
    Shiro
    SpringMVC
  • 原文地址:https://www.cnblogs.com/amywechat/p/5138684.html
Copyright © 2011-2022 走看看