简体   繁体   English

在ASP.NET项目中将本地dll放在哪里?

[英]Where to place local dll in a ASP.NET project?

I have a ASP.NET project where I need to pinvoke the following function: 我有一个ASP.NET项目,需要在其中调用以下功能:

[DllImport("NetSh.dll")]
public static extern int RunAsUsr(string pcs_admin, string pcs_user, string pcs_password);

The problem is that i get the following exception when I call the function: 问题是调用函数时出现以下异常:

Unable to load DLL 'NetSh.dll': The specified module could not be found. 无法加载DLL“ NetSh.dll”:找不到指定的模块。 (Exception from HRESULT: 0x8007007E) (来自HRESULT的异常:0x8007007E)

So, where I have to place my dll in order to avoid the exception? 因此,为了避免异常,我必须将dll放在哪里? At the moment the dll is in the same directory of my .aspx files. 目前,该dll位于我的.aspx文件的同一目录中。

It should be in bin folder in the root of your web app as your .Net assemblies are also located in the bin folder. 它应该位于Web应用程序根目录中的bin文件夹中,因为.Net程序集也位于bin文件夹中。

For web apps bin folder is default where .Net will search for files\\configs\\etc. 对于Web应用程序, bin文件夹是默认目录,.Net将在其中搜索files \\ configs \\ etc。 For windows app it will be the same folder where exe app is located. 对于Windows应用程序,它将是exe应用程序所在的文件夹。

By default you should put in the Bin folder of your project. 默认情况下,您应该放入项目的Bin文件夹。 if for some reason you do not want it there you could also specify a path for the DLL in the DLLIMPORT statement. 如果由于某种原因您不希望它存在,您还可以在DLLIMPORT语句中为DLL指定路径。

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

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