zoukankan      html  css  js  c++  java
  • Aspx改写成Html后缀方式的实现

    Aspx改写成Html后缀方式的实现

    系列文章目录

    一、伪静态方式(使用URLRewriter)
         1、改写方法    (文章地址:http://www.cnblogs.com/scottckt/archive/2011/01/12/1933737.html)
         2、回发时处理方法(文章地址:http://www.cnblogs.com/scottckt/archive/2011/01/12/1933791.html)
         3、将Aspx改写成HTml方法(文章地址:http://www.cnblogs.com/scottckt/archive/2011/01/12/1933836.html)

    二、真实改写(使用System.Web.Routing)(文章地址:http://www.cnblogs.com/scottckt/archive/2011/01/12/1933893.html)



    此实现与伪静态方式改写方法类似。我们仍然以微软提供的例子RewriterTester为例。

    1、引用DLL

      首先你要在你的项目里引用前边文章提到的两个DLL,分别是URLRewriter.dll和ActionlessForm.dll。

    2、配置WEB.CONFIG文件
    <configSections>
          
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
      
    </configSections>


    代码
      <RewriterConfig>
        
    <Rules>
          
    <!--
        Rules for Blog Content Displayer 
        为了便于观察结果。我把规则<LookFor>中的appx给删除了
    -->
          
    <RewriterRule>
            
    <LookFor>~/(\d{4})/(\d{2})/(\d{2})\.html</LookFor>
            
    <SendTo>~/ShowBlogContent.aspx?year=$1&amp;month=$2&amp;day=$3</SendTo>
          
    </RewriterRule>
          
    <RewriterRule>
            
    <LookFor>~/(\d{4})/(\d{2})/Default\.html</LookFor>
            
    <SendTo><![CDATA[~/ShowBlogContent.aspx?year=$1&month=$2]]></SendTo>
          
    </RewriterRule>
          
    <RewriterRule>
            
    <LookFor>~/(\d{4})/Default\.html</LookFor>
            
    <SendTo>~/ShowBlogContent.aspx?year=$1</SendTo>
          
    </RewriterRule>
          
    <RewriterRule>
            
    <LookFor>~/Default\.html</LookFor>
            
    <SendTo>~/Default.aspx</SendTo>
          
    </RewriterRule>
     ……


    <system.web>
      
    <httpHandlers> 
            
    <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> 
            
    <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> 
      
    </httpHandlers>
    </system.web>
     
    3、配置IIS解析.html文件
      IIS6.0配置方法

      网站->属性 ->虚拟目录->配置(G)...->映射->通配符应用程序映射->添加
      可执行文件:c:\windows\microsoft.net\framework\v2.0.50727 \aspnet_isapi.dll
      扩展名为:.html

      确认文件是否存在:不选.

      配置IIS7.5配置方法

      你的网站-->IIS中处理程序映射-->
      添加脚本映射(路径:*.html 可执行文件%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 名称:任意,比如Hml )
      添加通配符脚本映射(路径:* 可执行文件:C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 名称:任意,比如All)
      托管处理程序映射(路径:* 可执行文件:System.Web.UI.PageHandlerFactory 名称 任意 比如Html-Integrate)-------->
      IIS中 模块-->添加---->(名称:任意 如All 类型:URLRewriter.ModuleRewriter 把 仅针对向asp.net 应用程序或托管处理程序发出请求调用 勾上 ok )
      -->ok

    4、测试

      运行项目,在地址栏中输入 http://hostname/Default.html,服务器会指向http://hostname//Default.aspx的页面。


     参考文章:http://www.cnblogs.com/xiachufeng/archive/2010/08/29/1812063.html


     
  • 相关阅读:
    shell 函数
    PHP curl 实现RESTful PUT DELETE 实例
    call_user_func_array
    Laravel 文档中的 Service Providers
    window7主题破解与恢复(复制)
    ORM到底是用还是不用?(复制)
    关于cgi、FastCGI、php-fpm、php-cgi(复制)
    C语言赋初始值
    MySQL临时表的简单用法(复制)
    Mysql Having的用法:对group by之后的分组加限制条件(复制)
  • 原文地址:https://www.cnblogs.com/scottckt/p/1933836.html
Copyright © 2011-2022 走看看