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>
<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&month=$2&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>
……
<Rules>
<!--
Rules for Blog Content Displayer
为了便于观察结果。我把规则<LookFor>中的appx给删除了
-->
<RewriterRule>
<LookFor>~/(\d{4})/(\d{2})/(\d{2})\.html</LookFor>
<SendTo>~/ShowBlogContent.aspx?year=$1&month=$2&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>
……