简体   繁体   English

Server.CreateObject + 服务器上下文 + COM :-)

[英]Server.CreateObject + Server Context + COM :-)

I am implementing a COM component using .net for a few outdated components for a server migration task.我正在使用 .net 为服务器迁移任务的一些过时组件实现 COM 组件。

The old component was used to receive an image path on the current server, convert it to a jpeg and save the converted image in the same path.旧组件用于接收当前服务器上的图像路径,将其转换为 jpeg 并将转换后的图像保存在同一路径中。

This is trivial to do in .net, however my main problem is obtaining the server context.这在 .net 中很简单,但是我的主要问题是获取服务器上下文。 I am not sure how to do either one of the following:我不确定如何执行以下任一操作:

  1. saving the image to the same path that the original image was retrieved from将图像保存到检索原始图像的相同路径
  2. or sending the image directly to the response stream (avoiding the need to save the converted image)或者直接将图像发送到响应流(避免需要保存转换后的图像)

The component is being called within a class ASP page (yes, unfortunately!) using:该组件在类 ASP 页面中被调用(是的,不幸的是!)使用:

Server.CreateObject("Component.Class")

Is there anyway in the implementing .net code that I can obtain a reference to the Server object that created the component?无论如何,在实现 .net 代码中,我可以获得对创建组件的Server对象的引用吗? I was hoping that if I could obtain a reference to the server, I could then obtain the appropriate context to write back to the response stream.我希望如果我能获得对服务器的引用,我就能获得适当的上下文来写回响应流。

I have worked this out, obtaining a few clues for the internet and google.我已经解决了这个问题,为互联网和谷歌获得了一些线索。 Thought I should post this in case anyone else has the same problem.我想我应该发布这个以防其他人有同样的问题。

Obtaining the server context was a matter of including the following references:获取服务器上下文是包含以下参考的问题:

  1. COMSVCLib (should already be in your COM section when adding references to your project) COMSVCLib(添加对项目的引用时应该已经在您的 COM 部分)
  2. ASPTypeLibrary: Look for: "Microsoft Active Server Pages Object Library". ASPTypeLibrary:查找:“Microsoft Active Server Pages 对象库”。 If you don't see this immediately in your COM section, then you will need to add this from "windows programs and features".如果您没有立即在 COM 部分看到它,那么您需要从“windows 程序和功能”中添加它。 Add the following feature: Internet Information Services -> WWW Services -> ASP添加以下功能:Internet信息服务-> WWW服务-> ASP

Working out the above was the hardest thing :-) After that, its very simple to reference your server and other intrinsic ASP objects:解决上述问题是最困难的事情:-) 在那之后,引用您的服务器和其他内部 ASP 对象非常简单:

COMSVCSLib.AppServer aspServer = new COMSVCSLib.AppServer();
COMSVCSLib.ObjectContext oc = aspServer.GetObjectContext();
ASPTypeLibrary.Server server = (ASPTypeLibrary.Server)oc["Server"];

You can do the same with with other ASP objects such as Request and Response.您可以对其他 ASP 对象(例如请求和响应)执行相同操作。

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

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