MVC利用URLRoute实现伪静态后正真的静态html无法访问(转)

MVC通过URLRoute让网站某些页面成为伪静态

            //Mall/SomeNews/12.html
            routes.MapRoute(
                "News",                                              // Route name
                "Mall/{action}/{id}.html",                           // URL with parameters
                new { controller = "Mall", action = "NewDetails", id = "1" }  // Parameter defaults
            );

 

--------------------------------------------------------------------------------

win7+IIS7 测试一切正常

 

--------------------------------------------------------------------------------

win2003+iis6 测试不正常

对iis做如下配置:

主目录---应用程序设置下面配置---添加

可执行文件:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

扩展名:.html

动作:GET,HEAD,POST,DEBUG

脚本引擎打勾,确认文件是否存在去掉

 

-----------------------------------------------------------------------------

此时似乎html都交给MVC处理了   但是新的问题来了,正真的静态页面Link.html无法访问了

 

需要对web.config做如下配置:

 

1.找到<compilation >节点

加入如下内容最终结果

    <compilation debug="false">
      <buildProviders>
        <add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
      </buildProviders>
    </compilation>

 

2.找到<httpHandlers>节点

插入如下内容

    <add verb="*" path="*.html" type="System.Web.UI.PageHandlerFactory"/>

 

----------------------------------------------------------------------------

此时一切OK 静态和伪静态都能正常访问

posted on 2012-12-20 19:48  davidkam  阅读(615)  评论(1编辑  收藏  举报