【问题标题】:Using VBScript GetObject in C#在 C# 中使用 VBScript GetObject
【发布时间】:2014-07-25 06:03:31
【问题描述】:

我正在运行一个在其中运行网页的第三方应用程序。第三方应用程序包括一个位于服务器上的 dll。基本上我正在尝试替换与 C# 代码一起使用的当前 VB 脚本。

以下 vbscript 在网页中运行,并包含一个可以更改页面并完美运行的功能。

'VB Script
Set AgentDisp = GetObject("","AgentDisp.AgentDispatcher")
AgentDisp.ChangePage PageName, False

现在,当我在 C# 中通过添加对此 dll 的引用并在页面加载时运行以下代码来尝试相同的操作时,没有任何反应

// C#
var a = new AgentDisp.AgentDispatcher();
a.ChangePage("faq.aspx", false);

是否与 dll 的位置或实例有关?

【问题讨论】:

    标签: c# asp.net vbscript


    【解决方案1】:

    我不知道 C#,但您的代码似乎与 CreateObject 相同,但早期绑定。您需要使用 GetObject 等价物。

    GetObject 适用于正在运行的实例或数据文件。

    GetObject([pathname] [, class])
    
    When this code is executed, the application associated with the specified
    pathname is started and the object in the specified file is activated. If
    pathname is a zero-length string (""), GetObject returns a new object
    instance of the specified type. If the pathname argument is omitted,
    GetObject returns a currently active object of the specified type. If no
    object of the specified type exists, an error occurs.
    

    VBScript 也使用后期绑定(即 IDispatch)。您正在使用早期绑定。不过应该没关系。

    【讨论】:

    • 所以两个例子都在创建对象的新实例。
    • 如果省略路径名,则设置一个活动类。如果路径名为空,则创建一个新文档。 GetObject 也在 vb.net 中,与 vbscript 的完全相同。我无法从 C# 文档中做出正面或反面。我什至看不到有功能。所以把GetObject放在你项目的一个vb模块中。
    猜你喜欢
    • 1970-01-01
    • 2010-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多