简体   繁体   中英

Server.CreateObject + Server Context + COM :-)

I am implementing a COM component using .net for a few outdated components for a server migration task.

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.

This is trivial to do in .net, however my main problem is obtaining the server context. 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:

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? 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)
  2. ASPTypeLibrary: Look for: "Microsoft Active Server Pages Object Library". If you don't see this immediately in your COM section, then you will need to add this from "windows programs and features". Add the following feature: Internet Information Services -> WWW Services -> ASP

Working out the above was the hardest thing :-) After that, its very simple to reference your server and other intrinsic ASP objects:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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