我很确定stackoverflow.com是用ASP.NET创建的,但无论我在哪里点击,我都看不到地址栏中的.aspx扩展名.它是如何完成的,有什么特别的原因吗?
最有可能的是它通过URL重写完成...
网络服务器正在使用浏览器地址栏中的URL,并将其重新发布到幕后的ASPX页面
这可以在.NET HTTP模块中完成,也可以在IIS中作为ISAPI Handler完成
Scott Gutherie在他的网站上有一篇关于URL重写的好文章
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
您可以通过修改web.config文件来实现。
<configuration>
<system.webserver>
<rewrite>
<rules>
<rule name="RemoveASPX" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
</rules>
</rewrite>
</system.webserver>
</configuration>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
33778 次 |
最近记录: |