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中控制器不能同名问题
            );
        }
    
  • 相关阅读:
    css文本省略号
    javascript在数组的循环中删除元素
    ASP.NET MVC 微信公共平台开发之 微信接入
    ASP.NET Url重写
    通过FTP连接Azure上的网站
    UniversalApp启动页面设置
    ASP.NET页面动态添加js脚本
    使用HyperV虚拟机装系统
    使用一般处理程序HTTPHandler下载文件
    Egret Engine(白鹭引擎)介绍及windows下安装
  • 原文地址:https://www.cnblogs.com/amywechat/p/5138684.html
Copyright © 2011-2022 走看看