• 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中控制器不能同名问题
            );
        }
    
  • 相关阅读:
    hover经过放大效果
    TDD
    VisualStudio UnitTest FrameWork
    Rhino Mock
    Unit Test
    GPS坐标转化为百度坐标
    只上传APK而不进行反编译,在服务器集成第三方SDK。是如何实现的
    如何实现滑动scrollview上下隐藏
    Windroy、Windroye、Bluestacks运行Android实现原理
    问个file的问题
  • 原文地址:https://www.cnblogs.com/amywechat/p/5138684.html
Copyright © 2020-2023  润新知