Asp.net core 在IIS外部托管.NET核心应用程序
我正在尝试用Asp.net core 在IIS外部托管.NET核心应用程序,asp.net-core,hosting,kestrel,Asp.net Core,Hosting,Kestrel,我正在尝试用Kestrel托管.NET Core应用程序,但该应用程序不在IIS上。我似乎遇到以下错误: 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
Kestrel
托管.NET Core
应用程序,但该应用程序不在IIS
上。我似乎遇到以下错误:
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.'
杂项
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}";
}
}
节目
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;
}
}
启动
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();
}
}
为什么它试图在IIS上托管它?我必须指定我没有launchSettings.json
文件。它没有从.NET核心应用程序
模板创建一个。在IIS
之外运行时,我必须手动创建吗
如何使此服务器工作并在
IIS
外部运行?首先,launchSettings.json
仅用于开发。一旦部署应用程序,它将不会发布和使用
其次,CreateDefaultBuilder()
添加了IIS集成服务。但是,这并不意味着此时必须在IIS中托管。当然,您不应该仅仅因为包含了IIS集成而出现错误,但您没有在IIS中托管。如果我不得不冒险猜测,我会想象您运行的.NET Core SDK版本与服务器上安装的运行时版本不同。确保这两条线彼此对齐
如果您想完全摆脱IIS集成,则需要停止使用
CreateDefaultBuilder
,并手动执行它所做的操作,当然不包括添加IIS集成。您可以查看该方法正在处理什么。这样我就可以跳过UseKestrel
,useURL
。如何启动
服务器..等等。