简体   繁体   English

在IIS外部托管.NET Core应用程序

[英]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.

相关问题 在IIS 7中托管Asp.Net Core - Hosting Asp.Net Core within IIS 7 IIS 托管运行在 .Net Framework 上的 ASP Core? - IIS hosting ASP Core running on .Net Framework? 如何通过Visual Studio Team Services将.NET Core Web应用程序部署到IIS托管 - How deploy .NET Core web application via Visual Studio Team Services to hosting with IIS Kestrel / IIS 托管与 ASP.Net Core 2.2 / 3.0 应用程序切换 - Kestrel / IIS hosting toggling with ASP.Net Core 2.2 / 3.0 application 安装.net Core托管捆绑软件会使IIS上的所有现有应用程序池崩溃 - Installing .net core hosting bundle crashes all existing application-pools on IIS 在一个 IIS 应用程序池中托管两个 asp.net 核心项目 - Hosting two asp.net core projects in one IIS application pool 在 IIS 中托管 .net 核心应用程序。 无法加载配置。 属性“processPath”是必需的 - Hosting a .net Core application in IIS. Could not load configuration. Attribute 'processPath' is required 模拟不起作用 - Asp.Net core 3.1 应用程序与 Windows 身份验证托管在 IIS - Impersonation not working - Asp.Net core 3.1 application with Windows Authentication hosting in IIS 在共享Linux主机上托管ASP.NET Core应用程序 - Hosting ASP.NET Core application on shared Linux hosting .NET Core 2.2托管IIS在空闲后缓慢 - .NET Core 2.2 Hosting IIS slow after idling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM