问题
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