【发布时间】:2010-06-18 09:56:33
【问题描述】:
有选择地将 HTTP 请求重定向到 ASP.NET 页面到其 HTTPS 等效项的最简单和最有效的方法是什么?
例如,如果我的页面站点 URL 是 http://www.somesite.com,我想将部分(或全部)页面请求重定向到 https://www.somesite.com。
最简单的方法是什么?
【问题讨论】:
有选择地将 HTTP 请求重定向到 ASP.NET 页面到其 HTTPS 等效项的最简单和最有效的方法是什么?
例如,如果我的页面站点 URL 是 http://www.somesite.com,我想将部分(或全部)页面请求重定向到 https://www.somesite.com。
最简单的方法是什么?
【问题讨论】:
我使用此代码来执行此操作。
http://www.codeproject.com/KB/web-security/WebPageSecurity_v2.aspx
我想说,唯一的缺点是没有使用“正则表达式模式匹配”,但是很容易将它添加到代码中。
【讨论】:
取决于您使用的 IIS 版本以及您是否有权访问它以及您是否要编写自定义代码或配置产品功能。
IIS5、IIS6:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
IIS7、IIS7.5:
网址重写:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
以下是将http://.../checkout.aspx 重定向到 https 的规则示例:
<rule name="CheckoutToSSL" stopProcessing="true">
<match url="^checkout.aspx*" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
ASP.NET 路由:
http://msdn.microsoft.com/en-us/library/cc668201.aspx
IIS7、7.5重写和ASP.NET路由的区别
http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/
【讨论】: