【问题标题】:Call backend .NET dll from ASP.NET Web api从 ASP.NET Web api 调用后端 .NET dll
【发布时间】:2015-10-07 07:21:23
【问题描述】:

我正在构建客户端服务器应用程序。

业务逻辑在 C++ /CLI 中构建。 在同一个解决方案中,我有 ASP.NET Web api 项目。

对于登录,我在后端有方法。为了登录,我需要这样做

using Back_End;
public IHttpActionResult Logon([FromBody]Logon_Request model)
{
 string Answer = Back_End.Logon(model.Name, model.Password);
}

Back_End 在同一个解决方案中的 dll 内。

当我尝试调用 api/logon 时,它会重新调整我的异常。

{
"Message": "An error has occurred.",
"ExceptionMessage": "Could not load file or assembly 'Back_End, Version=1.0.5676.23091, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Attempt to load an unverifiable executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019)",
"ExceptionType": "System.IO.FileLoadException",
"StackTrace": ".........."
}

当然,因为它不在IIS服务器上。

最后是我的问题:

-但是我需要在服务器上部署我所有的业务逻辑 dll 吗?

-乳清在这里有用吗?

-有什么“更好”的方式来做我想做的事吗?

-也许我需要将其作为服务提供并拨打电话?但它将是 API for API。

【问题讨论】:

  • 将程序集/ .dll 添加到您的 Web 配置文件和 Login.aspx 的标记代码或包含登录信息的任何文件中。
  • 谢谢。你能说得更具体一点吗?在哪里,什么以及如何。我是 web api 的新手。 :)

标签: c# c++ asp.net visual-studio asp.net-web-api


【解决方案1】:

Web.Config 文件

<compilation debug="true" targetFramework="yourTargetFramework">
      <assemblies>
        <add assembly="yourAssemblyName, Version=yourAssemblyVersion, Culture=neutral, PublicKeyToken=yourPublicKeyToken" />
      </assemblies>
</compilation>

login.aspx 页面

<%@ Register Assembly="yourAssemblyName, Version=yourAssemblyVersion, Culture=neutral, PublicKeyToken=yourPublicKeyToken" Namespace=".dll Namespace" TagPrefix="name to call the loginUserControl" %>

例如。

...TagPrefix="rs" %&gt;

&lt;rs:Login/&gt;

【讨论】:

  • 这个异常听起来好像问题与 ASPX 页面无关。
  • 我在注册我的 .dll 时遇到了同样的错误,引用错误。一旦我添加了引用并删除了我的寄存器,或者从项目中删除了引用并将它们留在bin 文件夹中并在网页上注册它们,这个错误就消失了。
  • @usr 我相信我有一个错误引用的 .dll 是试图用一些潜在的非托管代码重新加载 .dll。认为这会是这里的问题吗?虽然我没有看到在他的场景中非托管代码会与托管代码混合在哪里。
  • 谢谢。我可以在星期一检查它。但我不觉得在我的情况下这将是什么解决方案。可能我需要建立服务。
猜你喜欢
  • 1970-01-01
  • 2017-08-01
  • 2013-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-15
  • 2021-09-24
  • 1970-01-01
相关资源
最近更新 更多