我正在运行iisnode并使用edge.js访问第三方DLL中的代码。此代码期望有一个web.config
文件,用于从中提取连接字符串。
\noderoot\bin\my3rdParty.dll
\noderoot\cs\myCode.cs
\noderoot\api.js
\noderoot\server.js
\noderoot\web.config
using System;
using System.Threading.Tasks;
using My3rdPartyNamespace;
public class Startup {
public async Task<object> Invoke(dynamic input) {
// My3rdPartyObject.DoSomeStuff() looks at ConfigurationManager.ConnectionStrings
return My3rdPartyObject.DoSomeStuff((string)input.someThing);
}
}
import {Router} from 'express';
import Edge from 'edge';
import path from 'path';
let router = Router();
router.post('/doAThing', (req, res, next) => {
let aThing = Edge.func({
source: path.join(__dirname, 'cs/myCode.cs'),
references: [
'System.Web.dll',
'./bin/my3rdParty.dll'
]
});
let payload = {
someThing: req.body.someThing
};
let response = aThing(payload, true);
res.json(response);
});
export default router;
我已经尝试将连接字符串放在iisnode使用的web.config
文件中,但显然edge.js看起来并不存在。当我将连接字符串放在node.exe.config
中并将该文件放在c:\program files\nodejs
中时,它会起作用,但这是一个不可接受的解决方案。
同样,我使用edge.js的全部意义是我可以使用第三方DLL,所以我不能简单地告诉DLL我的连接字符串是什么,除非我可以强行将其插入ConfigurationManager.ConnectionStrings
。
我不能使用edge-sql,因为我没有编写任何SQL - dll已经处理了SQL。我无法使用环境变量EDGE_SQL_CONNECTION_STRING
设置我的连接字符串,因为dll正在web.config
中查找具体命名的连接字符串。
想法?
答案 0 :(得分:3)
Edge.js不知道使用iisnode在IIS中托管,因此不使用web.config。 iisnode充当运行HTTP侦听器的node.exe的HTTP反向代理,该侦听器是应用程序的一部分。此node.exe和其中的任何代码都表现为您可以从命令行启动的独立应用程序。因此,Edge.js只会将node.exe.config文件与运行应用程序(https://github.com/tjanczuk/edge#how-to-appconfig)的node.exe可执行文件放在同一目录中。
我假设将连接字符串放在c:\program files\nodejs
中是不可接受的,因为它在机器上的多个应用程序之间共享,可能由不同的用户运行。
有一种解决方法。您可以使用nodeProcessCommandLine
配置属性(https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/iisnode.yml#L13)将iisnode配置为在自定义位置运行node.exe。具体来说,您可以将node.exe作为应用程序的一部分上载,指向nodeProcessCommandLine
以使用该专用副本,然后将node.exe.config
与您的连接字符串放在该私有node.exe旁边。
作为旁注,我建议将Edge.func
的调用放在全局范围内的代码片段中,以便它只运行一次而不是每次HTTP调用。