为了更能好的被搜索引擎找到,一般网站都会采用.html的形式,在ASP.NET中,我们也可以利用Mircosoft URLRewriter.dll来实现诸如Show.aspx?ID=1到1.html的转换,以下是实现的过程:
- 在工程中引用 URLRewriter.dll:http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx?mfr=true
- web.config的配置
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<!-- Rules for Blog Content Displayer -->
<RewriterRule>
<LookFor>~/(.[0-9]*)\.html</LookFor>
<SendTo>~/ArticleDetail.aspx?MyID=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers> - 在IIS中找到自己的虚拟目录网站,点属性,然后点配置,然后弹出应用程序配置对话框,选择添加,添加的可执行文件路径为c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,扩展名为.html