3

是否可以将混合无 cookie 会话与 cookie 会话一起使用?

我有一个捕获用户详细信息然后将付款重定向到 ssl 页面的应用程序。我想知道这是否可能?

http://www.mydomain.com/confirm.aspx

重定向到

https://www.mydomain.com/(S(za1tw2l2k02jer4fiskzlovd))/payment.aspx

注意:后一个 url 中的会话 ID。

因此,本质上,我们对大多数应用程序使用标准 cookie 会话,但是当我们转移到 ssl 页面时,我们将 SessionId 传递给 https url 以获取会话。我已经在本地尝试过,但它会启动一个新会话。

我错过了一个技巧吗?

谢谢

4

1 回答 1

2

我找到了一个似乎可行的解决方案

在 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);
            }
        }
    }

希望有人觉得这很有用,我被困了一段时间试图想出一个好的解决方案。

我的灵感来自这个网址

于 2011-03-20T11:09:07.063 回答