简体   繁体   English

如何将经典ASP响应对象传递给C#DLL

[英]How to pass the Classic ASP Response Object to a C# DLL

Can anyone tell me whether it is possible to pass the Response object from classic asp to a C# class library and if so how it is done. 谁能告诉我是否可以将Response对象从经典的ASP传递到C#类库,如果可以的话,如何完成。

I'm using C# 2010 express and JScript in ASP, but I'll take a VBScript answer. 我在ASP中使用C#2010 Express和JScript,但是我将使用VBScript答案。

Or if there is another way of outputting to the http context of the classic asp page from a dll, that'll also do. 或者,如果有另一种方法可以从dll输出到经典asp页面的http上下文,那么也可以。

I thinking that it can't be done as the System.Web.HttpResponse object doesn't seem to be available from a class library. 我认为这不能完成,因为类库中似乎没有提供System.Web.HttpResponse对象。

Thank you to those who responded. 谢谢那些回复的人。 By way of a complete answer for anybody else that may have the same question, here is some sample code: 对于可能遇到相同问题的其他人,作为一个完整的答案,下面是一些示例代码:

public string passObj(ASPTypeLibrary.Response r)
{
    r.Write("text from DLL");
    return "OK";
}

and on the classic asp side of things: 在经典的asp方面:

var x = Server.CreateObject("dllTest.test");
x.passObj(Response);

To access the classic ASP objects including Response, you can add a COM reference in your C# project to "Microsoft Active Server Pages Object Library". 若要访问包括响应的经典ASP对象,可以在C#项目中将COM引用添加到“ Microsoft Active Server Pages对象库”。

You can then reference it from C# as: 然后可以从C#引用为:

ASPTypeLibrary.Response

The Response object is a COM object that supports IUnknown and IDispatch . Response对象是一个支持IUnknown和IDispatchCOM对象 Therefore, you can pass it to a method as an object and call the properties using reflection. 因此,您可以将其作为对象传递给方法,并使用反射来调用属性。

From looking on my own machine, the IReponse IID is {D97A6DA4-D5F5-4763-9BE5-60126DD39E43} Typelib UUID is {A79CBB28-1006-4227-BE61-CBEE2520C353} . 从我自己的机器IReponse IIDIReponse IID{D97A6DA4-D5F5-4763-9BE5-60126DD39E43} UUID为{A79CBB28-1006-4227-BE61-CBEE2520C353} If you open regedit and navigate to HKEY_CLASSES_ROOT\\TypeLib\\{A79CBB28-1006-4227-BE61-CBEE2520C353}\\2.0\\0\\win32 the default key will contain a path to the Typelib you can import to create the interop assembly. 如果打开regedit并导航到HKEY_CLASSES_ROOT\\TypeLib\\{A79CBB28-1006-4227-BE61-CBEE2520C353}\\2.0\\0\\win32则默认密钥将包含您可以导入以创建互操作程序集HKEY_CLASSES_ROOT\\TypeLib\\{A79CBB28-1006-4227-BE61-CBEE2520C353}\\2.0\\0\\win32的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM