简体   繁体   English

C#ComVisible DLL仅在远程桌面连接时可由IIS使用

[英]C# ComVisible DLL only usable by IIS when Remote Desktop connected

I've created a ComVisible DLL which is signed with a given domain name (the company I work for). 我创建了一个ComVisible DLL,它使用给定的域名(我工作的公司)签名。 I place this DLL onto a customer's web host machine, which runs under a different domain, and register it using: C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\regsvcs 我将此DLL放在客户的Web主机上,该主机在不同的域下运行,并使用以下命令注册:C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ regsvcs

The DLL creates a XLSX file on a disk local to the customer's web host. DLL在客户的Web主机本地磁盘上创建XLSX文件。 The user can download this file with a browser. 用户可以使用浏览器下载此文件。

If I have a remote desktop session open to the customer's web host, the DLL acts as expected and the customer can download the temporary file which is created. 如果我有一个远程桌面会话打开到客户的Web主机,DLL将按预期运行,客户可以下载创建的临时文件。

However, as soon as I drop the remote desktop session (I don't log out and I leave the VPN connected), the DLL is no longer accessible. 但是,只要我放弃远程桌面会话(我没有注销并且我保持VPN连接),就不再可以访问DLL了。 The temporary file is no longer created by the asp classic site, and the customer of course is unable to stream the file which isn't created. asp经典站点不再创建临时文件,客户当然无法流式传输未创建的文件。

Any thoughts on what can cause this? 有什么可以导致这个的想法吗? The web server generates no errors. Web服务器不会生成错误。

I figured the DLL being signed with a different domain name then the web server hosts is part of the problem, but can't imagine why having a Remote Desktop session open (I just use mstsc by Microsoft) fixes the issue. 我认为DLL使用不同的域名签名然后Web服务器主机是问题的一部分,但无法想象为什么打开远程桌面会话(我只是使用Microsoft的mstsc)修复了这个问题。

In the end I removed the following code from AssemblyInfo.cs: 最后,我从AssemblyInfo.cs中删除了以下代码:

[assembly: ComVisible(true)]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(false,
    AccessChecksLevel = AccessChecksLevelOption.ApplicationComponent)]

I moved ComVisible and my Guid call to be a decorator on the class I want to expose to COM, and now the DLL always instantiates correctly and works without error. 我将ComVisible和我的Guid调用移动到我想要暴露给COM的类上的装饰器,现在DLL总是正确实例化并且无错误地工作。

I also now register using: 我现在也注册使用:

RegAsm.exe d:\foo\bar.dll /codebase /tlb

If you are working with XLSX files and getting this behavior I am fairly confident you are using the Office.Interop classes to do it. 如果您正在使用XLSX文件并获得此行为,我相信您正在使用Office.Interop类来执行此操作。 Using those interop COM classes are not supported from inside IIS . IIS内部不支持使用这些互操作COM类。 If you do try to use it from inside IIS you get the behavior exactly like you are describing. 如果您尝试从IIS内部使用它,您将获得与您描述的完全相同的行为。

You must switch to a different library like the Open XML SDK for Office to create the XLSX files instead. 您必须切换到不同的库,如Open XML SDK for Office,以创建XLSX文件。

The reason behind why it works once you RDP in is the interop dll's need a desktop session to function correctly. 一旦你进入RDP,它背后的原因是interop dll需要桌面会话正常运行。 While you are RDPed in there is a session for it to use, once you disconnect there is no-longer a session for it. 当你在RDPed中有一个会话供它使用时,一旦断开连接就不再有会话了。

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

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