[英]Hosting .NET Core Application outside IIS
I am trying to host a .NET Core
application with Kestrel
not on IIS
.And i seem getting the following error: 我正在尝试使用不在
IIS
上的Kestrel
托管.NET Core
应用程序,并且似乎出现以下错误:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.AspNetCore.Server.IISIntegration, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'
MISC MISC
class Address {
public string ProtocolType { get; set; } = "http";
public string Host { get; set; }
public long Port { get; set; }
public static Address Default = new Address { Host = "localhost", Port = 9300, ProtocolType = "http" };
}
static class AddressExtensions {
public static string ToUrl(this Address @this) {
return $"{@this.ProtocolType}//{@this.Host}:{@this.Port}";
}
}
Program 程序
public class Program {
public static void Main(string[] args) {
CreateWebHostBuilder(args).Build().Start();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
var builder=WebHost.CreateDefaultBuilder(args); //crashes here !!
builder.UseStartup("Startup");
var url = Address.Default.ToUrl();
builder.UseKestrel().UseUrls(url);
return builder;
}
}
Startup 启动
public class Startup {
public void ConfigureServices(IServiceCollection services) {
services.AddMvcCore();
}
public void Configure(IApplicationBuilder app) {
app.Map("/http", x => x.UseMvc());
app.Map("/ws", x => {
});
app.UseMvc();
}
}
Why does it try to host it on IIS
? 为什么要尝试在
IIS
上托管它? I must specify that i do not have a launchSettings.json
file. 我必须指定我没有
launchSettings.json
文件。 It did not create one from the .NET Core App
template.Do i have to do it manually for running outside of IIS
? 它不是从
.NET Core App
模板创建的。我是否必须手动在IIS
之外运行它?
How can i make this server work and run outside IIS
? 如何使该服务器正常工作并在
IIS
外部运行?
First, launchSettings.json
is only for development. 首先,
launchSettings.json
仅用于开发。 It is not published and not used once the app is deployed. 部署应用程序后,它不会发布也不会使用。
Second, CreateDefaultBuilder()
, among other things, adds the IIS integration services. 其次,
CreateDefaultBuilder()
等添加了IIS集成服务。 However, that doesn't mean that you have to host in IIS at that point. 但是,这并不意味着您此时必须托管在IIS中。 You certainly shouldn't be getting an error just because the IIS integration is included, but you're not hosting in IIS.
当然,您不应该因为包含IIS集成而收到错误消息,但您不是在IIS中托管。 If I had to hazard a guess, I'd imagine you're running a different version of the .NET Core SDK than the runtime that's installed on your server.
如果我不得不冒险猜测的话,我想您正在运行与服务器上安装的运行时不同的.NET Core SDK版本。 Make sure that the two are in line with each other.
确保两者相互对齐。
If you want to get rid of the IIS integration altogether, you'll need to stop using CreateDefaultBuilder
and do what it does manually, minus of course the adding of the IIS integration. 如果您想完全摆脱IIS集成,则需要停止使用
CreateDefaultBuilder
并手动执行它,当然要减去IIS集成。 You can view the source to see what the method is taking care of. 您可以查看源以查看该方法要处理的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.