我正在使用IIS7的URLRewrite功能在我的ASP.NET WebForms应用程序的URL中隐藏.aspx
扩展名。如何阻止使用IIS7的URLRewrite模块直接访问.aspx页面?
我使用了以下配置:
<rule name="WebFormsToMVC" stopProcessing="true">
<match url="^(.*?)\.aspx\?*?.*$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}" />
</rule>`
我现在就可以浏览到:
http://www.mytest.com/contact
,这被改写为:
http://www.mytest.com/contact.aspx
这保留“pr etty“url在浏览器地址栏中。我还更新了网站上的所有链接以使用无扩展名的网址。
问题是,底层的.aspx
页仍然可以直接访问,我想要阻止这一点。
如果用户浏览到http://www.mytest.com/contact.aspx
我希望它重定向/重写为http://www.mytest.com/contact
,或者至少返回一个“找不到页面”。
更新:
我设法通过重定向所有.aspx
页面到主目录得到这个工作。这并不理想,因为我宁愿将它们发送到非.aspx
版本,但它现在就会完成。
<rule name="Block .aspx" stopProcessing="true">
<match url=".aspx" />
<action type="Redirect" url="/" />
</rule>`
如何重写和重新导向网址,直接解决.aspx
网页对我友好的URL格式?
谢谢,多数民众赞成我正在寻找,我以为我试过,但也许我的语法有点不对。 – 2011-04-01 11:38:20