Running Edge.js from an ASP.NET MVC project
I'm having an interesting time trying to get Edge.js running from an ASP.NET MVC project. From the Edge documentation, the basic console application is this:
public static async Task Start()
{
var func = Edge.Func(@"
return function (data, callback) {
callback(null, 'Node.js welcomes ' + data);
}");
Console.WriteLine(await func(".NET"));
}
static void Main(string[] args)
{
Start().Wait();
}
and this works with no problem on my machine. The next step is to create an ASP.NET MVC project, and to try to run the same script from a form-driven controller action. The ASP.NET MVC project runs on IIS Express by default.
This is the controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public async Task<ActionResult> TestEdge()
{
try
{
var func = Edge.Func(@"
return function (data, callback) {
callback(null, 'Node.js welcomes ' + data);
}");
Console.WriteLine(await func(".NET"));
return RedirectToAction("Index");
}
catch (Exception ex)
{
Console.WriteLine(ex.GetBaseException().Message);
return RedirectToAction("Index");
}
}
}
Unfortunately, the call to Edge.Func
blows up. The exception is
System.DllNotFoundException was unhandled
Message: An unhandled exception of type 'System.DllNotFoundException' occurred in EdgeJs.dll
Additional information: Unable to load DLL 'node.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I have Edge installed globally (via npm install edge -g).
I have tried copying the node.dll
file directly into the bin folder, but that generates a BadImageFormat exception.
According to the Edge.js documentation, "Using Node.js via Edge.js in ASP.NET web applications is no different than in a .NET console application". However, this is the simplest possible implementation in an ASP.NET application, so there must be some difference. As per the suggestion in the documentation, I also tried copying the node_modules
subdirectory into the bin
folder of the web app, but this did not help.
Any further suggestions will be appreciated.
Uninstalling and reinstalling the Edge.js NuGet package fixed this for me.
To migrate from IIS Express to IIS, you'll need an installation of iisnode.
链接地址: http://www.djcxy.com/p/31312.html