【问题标题】:How to pass the entire contents of Classic ASP session to .net code?如何将经典 ASP 会话的全部内容传递给 .net 代码?
【发布时间】:2012-10-10 02:44:04
【问题描述】:

我知道如何从经典 ASP 站点(Server.CreateObject、gacutil 和所有其他站点)调用 .net 代码的练习。我说的是从 VBScript 代码调用 .net DLL。 (这与 ASP.net 无关)

我想知道的是,如何将整个 Classic ASP 会话的内容传递给 .net 代码。我想我想将Session.Contents 传递给.net 代码,但我不知道如何编写一个可以接受该对象的接口。

如果您还可以告诉我如何传递Request.FormASPError 对象的全部内容,则可以加分。

【问题讨论】:

标签: asp-classic


【解决方案1】:

假设您说“从 VBScript 代码调用 .net DLL”时是指 Set invokedNetDLL = CreateObject("MyNamespace.MyType"),我会尝试以下操作:

<%
    Dim key
    Dim serializedSession
    Dim invokedNetDLL

    For Each key in Session
        serializedSession = key & "=" & Session(key) & "&"
    Next

    'Trim last &
    serializedSession = Left(serializedSession, Len(serializedSession) - 1)

    Set invokedNetDLL = CreateObject("MyNamespace.MyType")
    invokedNetDLL.MyMethod(serializedSession)

%>

Request.Form而言,同样的方法可以应用:

<%
    Dim key
    Dim serializedSession
    Dim serializedRequestForm
    Dim invokedNetDLL

    For Each key in Request.Form
        serializedRequestForm = key & "=" & Request.Form(key) & "&"
    Next

    'Trim last &
    serializedRequestForm = Left(serializedRequestForm, Len(serializedRequestForm) - 1)

    For Each key in Session
        serializedSession = key & "=" & Session(key) & "&"
    Next

    'Trim last &
    serializedSession = Left(serializedSession, Len(serializedSession) - 1)

    Set invokedNetDLL = CreateObject("MyNamespace.MyType")
    invokedNetDLL.MyMethod(serializedRequestForm, serializedSession)

%>

我还没有测试过这段代码,但这就是我要开始的地方。

【讨论】:

  • 我明白了......换句话说,我可以“字符串化”我想要保存的值。我希望该框架可以提供一些更优雅的东西,但如果我找不到其他东西,我肯定会做这样的事情!
  • 也许像 XML 或 JSON 这样的东西是合适的,因为它有转义保留字符和所有字符的约定。
  • 我使用QueryString-style 转义(因为我不知道您的 .NET 版本),认为它很容易解码,尽管您当然可以将其字符串化为 XML 或 JSON(或自定义格式)。此外,这个答案假设您可以在 Classic ASP 中循环访问我尚未测试过的 StateBag。除非您将对象保留在 Session 中,否则这应该可以工作,在这种情况下,您还必须将它们序列化为原语。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-15
相关资源
最近更新 更多