わかりましたので、ASP.NET MVC サイトの一部で https/ssl を強制したいと思います。ここに ActionFilter を含む多くの優れたソースが見つかりました: http://blog.tylergarlick.com/index.php/2009/07/mvc-redirect-to-http-and-https/
しかし、ActionFilter を有効にするたびに、リダイレクト ループに陥ります。問題は、アドレス バーに https://www.mysite.com/ と入力すると、 request.urlが常にhttp://www.mysite.com/になることです。
アクション フィルターのコードは以下のとおりです。私の知る限り、URL の書き換え、リダイレクト、カスタム ルーティング、または標準設定以外の URL の変更は行っていません。これが発生する一般的/まれな理由や、回避策や修正方法はありますか? このサイトは現在 NetworkSolutions でホストされています - IIS 構成に関連している可能性はありますか? どんな援助でも大歓迎です。
public class RedirectToHttps : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Helpers just so I don’t have to type so much
var request = filterContext.HttpContext.Request;
var response = filterContext.HttpContext.Response;
// Make sure we’re in https or local
if (!request.IsSecureConnection && !request.IsLocal)
{
string redirectUrl = request.Url.ToString().Replace("http:", "https:");
response.Redirect(redirectUrl);
}
base.OnActionExecuting(filterContext);
}
}