ASP.NET 如何实现伪静态 其实所谓的伪静态页面,就是指的URL重写.
1.首先在web.config里写 <configSections> <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/> </configSections>
2.在web.config里添加以下节点 <httpHandlers> <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/> <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/> </httpHandlers>
3.配置重写URL规则 (这里我们就以 *.html转到*.aspx为例子,当然也可以实现 http://www.a.com/a-1.html 转到 http://www.a.com/a.aspx?id=1 这种形式),
在configuration 加入一下节点 <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/index.html</LookFor> <SendTo>~/index.aspx</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/Default.html</LookFor> <SendTo>~/Default.aspx</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/aboutus.html</LookFor> <SendTo>~/aboutus.aspx</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/aboutus_(\d+).html</LookFor> <SendTo>~/aboutus.aspx?ID=$1</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/Newslist.html</LookFor> <SendTo>~/Newslist.aspx</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/Newslist_(\d+).html</LookFor> <SendTo>~/Newslist.aspx?ID=$1</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/Newsview_(\d+).html</LookFor> <SendTo>~/Newsview.aspx?id=$1</SendTo> </RewriterRule> </Rules> </RewriterConfig>
参考:http://hi.baidu.com/style_lifee/blog/item/b52a4adb11c4b40263279821.html
|