How to self-host ASP.NET 5 MVC6 application

非 Y 不嫁゛ 提交于 2019-12-07 12:32:38

问题


Just started learning ASP.NET 5 / MVC 6 I'm curious about self-hosting such an app outside of IIS - as a Windows service. Should I be using TopShelf for that, like it was the case with OWIN/Katana apps, or does ASP.NET 5 provide some built-in self-hosting (as a service) options via a NuGet package?


回答1:


You can use the Kestrel library for self-hosting. Add dependency to the library in the project.json file:

"dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    // Dependencies deleted for brevity.
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
}

Then scecify this command for Kestrel:

"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
}

You can start it by command line from the folder with your MVC project:

dnx web

Please, notify that dnvm must be runned before.




回答2:


All ASP.NET Core applications are self-hosted.

Yes you read it right!

public class Program
{
    public static void Main(string[] args)
    {
        var config = new ConfigurationBuilder()
            .AddCommandLine(args)
            .AddEnvironmentVariables(prefix: "ASPNETCORE_")
            .Build();

        var host = new WebHostBuilder()
            .UseConfiguration(config)
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration() //// Here IIS integration is optional
            .UseStartup()
            .Build();

        host.Run();
    }
}

Have a look here for more details.



来源:https://stackoverflow.com/questions/35330609/how-to-self-host-asp-net-5-mvc6-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!