3

我有一个基于 ASP.NET 5 RC1 final 预览模板的应用程序。我通过运行发布应用程序

dnu publish --no-source --runtime active --configuration Release

生成的包包含运行时“dnx-clr-win-x64.1.0.0-rc1-final”。

当我将包复制到另一台 Windows 机器并尝试在 output\approot 目录中运行 web 命令时,我收到以下错误:

Error: Unable to load application or execute command 'Microsoft.AspNet.Server.WebListener'. Available commands: web, webListener.
System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
   at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
   at System.Reflection.Assembly.LoadFile(String path)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadFile(String assemblyPath)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
   at Microsoft.Dnx.Host.LoaderContainer.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.ResolveAssembly(Object sender, ResolveEventArgs args)
   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)

我已经尝试过 Kestrel 和 WebListener,同样的错误信息。该软件包适用于我的机器。

为了让应用程序在另一台机器上运行,还有什么需要做的吗?

4

3 回答 3

2

要自托管应用程序,我有:

  • 部署到文件系统(到我的开发机器的 c 驱动器)
  • 将 Hosting.ini (C:[app-name]\approot\src[app-name]\ 中的条目 Localhost:5000 (默认)) 更改为我机器的 IP 地址
  • 在我机器的 windows 防火墙中打开了 5000 端口

然后,我能够通过 LAN 从另一台机器加载应用程序。
注意你必须以管理员身份启动 web.cmd
之后,我在我们的 Intranet-server 上做了同样的事情(将整个部署目录复制到 Intranet-server 的 c:-drive,更改了 hosts.ini 中的 IP到 server-ip 并在 Intranet-server 上的 Windows 防火墙上打开端口 5000)。
然后我在 Intranet-server 上以管理员身份启动 web.cmd,并且该应用程序可在 LAN 中访问(服务器 IP:5000 或 DNS 名称:5000)。
注意:我刚刚更新到 RC1,项目模板似乎有各种变化(因此,我从头开始重新创建了我的小示例项目)。
特别是 Hosting.ini 文件(我已将 Localhost 条目更改为机器 IP)没有生成/支持记录器。
我还没有找到任何描述,而是如何更改 IP(根据 MS,hosting.json 文件中的新内容),但发现可以在 project.json 中更改它-文件。
我改变了:

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://172.16.1.7:5000",
    "ef": "EntityFramework.Commands"
  },

现在,它又可以工作了。
但是注意!
我确定应该以另一种方式完成(根据hosting.json-file中的MS)但是-正如我所写-我没有找到hosting.json-file中条目的任何描述,但找到了提示网上找老版本怎么弄,在project.json-file里。

因此,仅将此作为临时解决方法,直到我们知道如何正确处理!
并且只在已部署的目录中执行此操作(而不是在 VS-project 中,否则,本地 dev-is 将不再运行!

于 2015-11-19T18:28:48.817 回答
2

该问题可以通过使用 7-zip 而不是 Windows 资源管理器提取 ZIP 文件来解决,另请参阅:.net local assembly load failed with CAS policy

感谢@Kiran Challa 的链接。

于 2016-02-05T09:11:14.823 回答
0

@martin klinke 建议使用 7-zip 的替代方法,您可以使用streams -s -d *.*来自sysinternals / technet 的命令。

这将取消阻止标记为“不安全”的文件(请参阅Martin 提供的链接)。

这将递归地取消阻止文件(在您的 zip 的根目录中运行它)。

于 2016-03-09T08:01:57.180 回答