AppHarborでホストされている asp.net 3.5 でアプリケーションを構築しました。問題は、HTTPS で URL 書き換えが機能しないことです。以下は、SSL で一部のページを実行するためのコードです。
string CurrentUrl = Request.Url.ToString();
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
string sDir = oInfo.Directory.Name;
pageName = sRet;
if (sRet == "Register.aspx" || sRet == "Login.aspx" || sRet == "Post.aspx" || sRet == "ChangePassword.aspx" || sRet == "ChangeUserStatus.aspx" || sRet == "Verification.aspx" || sRet == "ContactInfo.aspx" || sRet == "Find.aspx" || sRet == "MyAccount.aspx" || sRet == "MyEmailAddresses.aspx" || sRet == "Load.aspx" || sRet == "MyPostedLoads.aspx" || sRet == "MySubmittedBids.aspx" || sRet == "MySavedAddresses.aspx" || sRet == "MyCarriers.aspx" || sRet == "MyPotentialLoads.aspx" || sRet == "MyFreightAlarms.aspx" || sRet == "MyFreightAlarmsPreferences.aspx" || sRet == "MyAddress.aspx" || sRet == "GetUserComments.aspx" || sRet == "MyCreditCard.aspx" || sRet == "MyWallet.aspx" || sRet == "InvoiceMe.aspx" || sRet == "MyShippers.aspx" || sRet == "MyCoWorkers.aspx" || sRet == "MyACH.aspx" || sRet == "RouteMap.aspx" || sRet == "Pricing.aspx" || sRet == "PricingPayment.aspx" || sRet == "PaymentProcessed.aspx")
{
string NewUrl = "";
if (!Request.IsSecureConnection && !string.Equals(HttpContext.Current.Request.Headers["X-Forwarded-Proto"], "https", StringComparison.OrdinalIgnoreCase))
{
NewUrl = Regex.Replace(CurrentUrl,
@"^https?(://[^/:]*)(:\d*)?",
"https$1",
RegexOptions.IgnoreCase);
Response.Redirect(NewUrl);
}
}
また、web.config での URL 書き換えのルールは次のとおりです。
<rewrite>
<rules>
<rule name="Rewrite with .aspx" stopProcessing="true">
<match url="^([^\.]+)$" />
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
<rule name="Redirect .aspx page requests" stopProcessing="true">
<match url="(.+)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
</rules>
</rewrite>
問題は、そのページが無限ループに残り、適切にリダイレクトできないことです。