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

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

问题描述

取决于Microsoft文档:





在上述示例中,Visual Studio将将我的应用托管在IIS Express中(带有打勾的项目)。如果要作为Kestrel托管应用程序运行它,则从下拉列表中选择 WebApplication2 。现在,当我启动该应用程序时,它将在命令提示符窗口中运行。



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

 公共类程序
{
公共静态无效Main(string [] args)
{
BuildWebHost(args).Run();
}

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

在幕后(在 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天全站免登陆