我正在进行一个快速沙盒测试,测试内容涉及Rewritten URLs(示例来自Scott Guthrie的博客)和表单身份验证/授权。
我的设置非常简单。
~/View/(\d{1,6}) => ~/Public/View.aspx?ContentID=$1
AND
~/Buy/(\d{1,6}) => ~/Private/Purchase.aspx?ContentID=$1
我已确认URL重写功能可通过分别浏览以下网址来使用:
- http://localhost/urltest/Public/View.aspx?contentID=123456
- http://localhost/urltest/View/123456
- http://localhost/urltest/Private/Purchase.aspx?contentID=123456
- http://localhost/urltest/Buy/123456
<location path="Private">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="Public">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
当我浏览到这两个原始网址(.aspx文件)时,它完美地运行,但是当我浏览到URL重写版本时,它根本没有触发。
我尝试为Buy
分别添加<location>
部分,但这仍然无法引起授权/身份验证模块的启动。
可能是因为它没有将这些URL视为ASPX资源...我可以通过使重写规则查找来解决此问题。
<LookFor>~/Buy/(\d{1,6})\.aspx</LookFor>
即强制重写版本以ASPX结尾,但这似乎很丑陋。 是否有任何方法可以使身份验证处理程序对任何url类型都触发,而不考虑扩展名(或缺少扩展名)?