在C#中使用VBScript GetObject

时间:2014-07-24 11:59:33

标签: c# asp.net vbscript

我正在运行第三方应用程序,该应用程序在其中运行网页。第三方应用程序包含一个位于服务器上的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的位置或实例有关?

1 个答案:

答案 0 :(得分:0)

我不知道C#,但您的代码看起来与CreateObject相同但是早期绑定。您需要使用GetObject equiv。

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)。您正在使用早期绑定。尽管如此。