【问题标题】:Session FROM ASP.NET to classic asp从 ASP.NET 到经典 asp 的会话
【发布时间】:2013-01-31 18:40:06
【问题描述】:

我有一个旧系统,不是我自己用经典的 ASP 开发的。 我有一个新系统,由我在 ASP.NET 中开发

如何将会话变量(不是复杂类型,只是简单的字符串或 int)传递到该经典 ASP 页面?我不需要任何回报。

要在作品中添加扳手 - 如果经典 ASP 站点位于不同的域中,我该如何进行“移交”或转移?

更新: 不能使用通过查询字符串传递项目或将其存储在数据库中并让经典 ASP 从数据库中读取它的选项。

谢谢

【问题讨论】:

  • 不使用查询字符串了吗?
  • 正确的 andorbal - 使用 QS 是不可能的,因为旧的经典 asp 系统检查会话的值,如果它不存在,它会做一些时髦的事情......不希望它通过时髦的部分:)
  • 我将在查询字符串中对其进行加密,并在 asp 站点中修改会话“时髦”区域。您将无法将会话对象传递给经典 asp,尤其是在不同的域上。执行此操作的所有其他方式都是“黑客”,并且不是很安全,因此您应该对其进行加密。
  • 是的。我不得不恢复到这个.... eesh

标签: asp.net session asp-classic


【解决方案1】:

我有不同的方向。我通过 cookie 交换了会话状态。添加这些方法。所以现在我没有直接调用 Session,而是使用这些方法。

ASP.NET

 public static void AddSessionCookie(string key, string value)
    {
        var cookie = HttpContext.Current.Request.Cookies["SessionCookie"];
        if (cookie == null)
        {
            cookie = new HttpCookie("SessionCookie");
            cookie.Expires = DateTime.Now.AddHours(12);
            HttpContext.Current.Response.Cookies.Add(cookie);
            HttpContext.Current.Request.Cookies.Add(cookie);
        }

        HttpContext.Current.Session[key] = value;
        cookie[key] = value;
    }
    public static string GetSessionCookie(string key)
    {
        if (HttpContext.Current.Session[key] == null)
            return string.Empty;

        string cook = HttpContext.Current.Session[key].ToString();
        if (!String.IsNullOrEmpty(cook))
        {
            var cookie = HttpContext.Current.Request.Cookies["SessionCookie"];
            if (cookie == null)
            {
                cookie = new HttpCookie("SessionCookie");
                cookie.Expires = DateTime.Now.AddHours(12);
                HttpContext.Current.Response.Cookies.Add(cookie);
                HttpContext.Current.Request.Cookies.Add(cookie);
            }
            if (cookie != null)
                cookie[key] = cook;

            return cook;
        }
        return cook;
    }

那么经典

Function AddSessionCookie(key, value)

    Response.Cookies("SessionCookie")(key)= value
Response.Cookies("SessionCookie").Expires = DATE + 1
Session(key) = value

End Function

  Function GetSessionCookie(key)

If Session(key) <> "" Then
Response.Write(Session(key))
ELSEIF Response.Cookies("SessionCookie")(key) <> "" THEN
Session(key)=Response.Cookies("SessionCookie")(key)
Set GetSessionCookie = Session(key)
End If
End Function

【讨论】:

    【解决方案2】:

    您可以使用经典的 asp 页面来设置会话变量,例如发布参数。

    然后从你的 asp.net 页面调用那个经典的 asp 页面。

    示例(不完整)session.asp:

    if session("userIsloggedIn") = true and request.form("act") = "setSessionVar" then
        session(request.form("name")) = request.form("value")
    end if
    

    当然,这是某种 hack,但我们谈论的是经典的 asp...

    【讨论】:

      猜你喜欢
      • 2014-10-14
      • 1970-01-01
      • 2016-04-15
      • 2011-04-29
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多