我找到了一个似乎可行的解决方案
在 http 和 https 之间传输时,我有以下内容:
如您所见,我将会话 ID 手动传递给 https 页面。
protected void btnPurchase_Click(object sender, EventArgs e)
{
// Confirm puchase code **
string sslPaymentPath = string.Format("https://{0}/payment.aspx?sid={1}", Request.Url.DnsSafeHost, Session.SessionID);
Response.Redirect(sslPaymentPath);
}
到达 ssl 页面后,asp.net 将请求视为新会话,因此我使用 global.asax 中的 Start_Session 方法放弃新创建的会话并添加一个新的会话 cookie,其中会话 ID 是从查询字符串传入的。因为此时填充会话 keyValue 对的 AquireSessionState 已经运行,所以我需要将页面重定向回自身以重新填充这些值。
它似乎工作得很好:)
void Session_Start(object sender, EventArgs e)
{
bool isPaymentPage = (Request.Path.ToLower().IndexOf("payment.aspx") != -1);
// Code to load session over ssl. When changing between two sessions
if (isPaymentPage && Request.QueryString["sid"] != null && Request.IsSecureConnection)
{
string passedSessionId = Request.QueryString["sid"];
Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", passedSessionId));
Response.Redirect(Request.Url.LocalPath, true);
}
}
此外,关于有人在浏览 ssl purchase.aspx 页面时单击外部链接,我在 global.asax 中编写了以下内容,以将流量重定向回标准的非 ssl 页面(如果它不是付款页面)。
void Application_BeginRequest(object sender, EventArgs e)
{
bool isPaymentPage = (Request.Path.ToLower().IndexOf("payment.aspx") != -1);
// In the case someone has navigated away from the payment page redirect them back to the none secure protocol.
if (!isPaymentPage && Request.IsSecureConnection)
{
bool isAxdResource = (Request.Path.ToLower().IndexOf(".axd") != -1);
if (!isAxdResource)
{
string url = Request.Url.AbsoluteUri.ToLower().Replace("https://", "http://");
Response.Redirect(url,true);
}
}
}
希望有人觉得这很有用,我被困了一段时间试图想出一个好的解决方案。
我的灵感来自这个网址。