在没有 IIS 和 VS 2017 的情况下使用 Kestrel [英] Using Kestrel Without IIS and VS 2017

查看:21
本文介绍了在没有 IIS 和 VS 2017 的情况下使用 Kestrel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

依赖于微软文档:

在上面的示例中,Visual Studio 将在 IIS Express(带勾号的项目)中托管我的应用程序.如果您想将它作为 Kestrel 托管应用程序运行,那么我会从下拉列表中选择 WebApplication2.现在,当我启动应用程序时,它将从命令提示符窗口运行.

如果您使用的是 .NET Core 2.0,那么您的 Program.cs 文件应如下所示:

公共类程序{public static void Main(string[] args){BuildWebHost(args).Run();}公共静态 IWebHost BuildWebHost(string[] args) =>WebHost.CreateDefaultBuilder(args).UseStartup<启动>().建造();}}

在幕后(在 Build() 方法中)ASP.NET Core 将添加调用以确保您的应用程序将在 IIS 和 Kestrel 中运行,而无需您进行任何更改.

Dependent on Microsoft Documentation:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/?view=aspnetcore-2.0&tabs=aspnetcore2x

Kestrel can be used by itself or with a reverse proxy server, such as IIS, Nginx, or Apache. A reverse proxy server receives HTTP requests from the Internet and forwards them to Kestrel after some preliminary handling.

IIS, Nginx, and Apache can't be used without Kestrel or a custom server implementation. ASP.NET Core was designed to run in its own process so that it can behave consistently across platforms.

But when i run the visual studio 2017, always IIS Express runs. So how to depend on kestrel alone if that is possible dependent on MS documentation.

解决方案

You can change the startup application from the toolbar in VS2017

In the example above Visual Studio will host my app in IIS Express (the item with the tick). If you want to run it as a Kestrel hosted application then I would select WebApplication2 from the drop down. Now, when I start the application it will run from a command prompt window.

If you are using .NET Core 2.0 then your Program.cs file should look something like this:

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
    }
}

Behind the scenes (in the Build() method) ASP.NET Core will add the calls to ensure you app will run within IIS and Kestrel without you needing to change anything.

这篇关于在没有 IIS 和 VS 2017 的情况下使用 Kestrel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆