asp.net你可以将cookieless与cookie会话存储的会话数据混合在一起吗?

时间:2011-03-19 20:50:03

标签: asp.net session-cookies cookieless

是否可以在cookie会话中使用混合的无Cookie会话?

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

  

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

     

重定向到

     

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

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

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

我错过了一招吗?

由于

1 个答案:

答案 0 :(得分: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);
            }
        }
    }

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

我的灵感来自this url

相关问题