http://msdn.microsoft.com/zh-cn/library/ms972974.aspx这里下的URLRewriter,在配置文件里进行了如下配置 <RewriterConfig>
<Rules>
<RewriterRule>
<LookFor><![CDATA[~/(\d*)/test\.aspx]]></LookFor>
<SendTo><![CDATA[~/test.aspx?id=$1]]></SendTo>
</RewriterRule> <RewriterRule>
<LookFor><![CDATA[~/abc(/*)]]></LookFor>
<SendTo><![CDATA[~/default.aspx]]></SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>是想将 http://localhost/123/test.aspx转发到http://localhost/test.aspx?id=123http://localhost/abc/转发到http://localhost/default.aspx在VS里直接运行是没有问题的,当放到IIS里,第二个就不行了,为什么?如何才能达到我想要的结果,http://localhost/abc/转发到http://localhost/default.aspx
<Rules>
<RewriterRule>
<LookFor><![CDATA[~/(\d*)/test\.aspx]]></LookFor>
<SendTo><![CDATA[~/test.aspx?id=$1]]></SendTo>
</RewriterRule> <RewriterRule>
<LookFor><![CDATA[~/abc(/*)]]></LookFor>
<SendTo><![CDATA[~/default.aspx]]></SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>是想将 http://localhost/123/test.aspx转发到http://localhost/test.aspx?id=123http://localhost/abc/转发到http://localhost/default.aspx在VS里直接运行是没有问题的,当放到IIS里,第二个就不行了,为什么?如何才能达到我想要的结果,http://localhost/abc/转发到http://localhost/default.aspx
解决方法有两种,一种是修改iis配置,把所有文件类型交给asp.net扩展处理
还有一种更简单,在abc目录下放一个空的default.aspx文件,修改重写规则如下
<RewriterRule>
<LookFor><~/abc/default.aspx></LookFor>
<SendTo><~/default.aspx></SendTo>
</RewriterRule>
因为我是想把 username/转发到 userPage.aspx?user=userName
就是在iis里也要配置,我是转html的,要添加一个后缀是html。
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
<!--使用*时不能加载css-->
<add verb="*" path="*" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>