Comment pouvons-nous définir ContentRootPath et WebRootPath?

Nous sommes en terminant par la suite ContentRoot et WebRoot lorsque nous avons organisé notre application à partir de IIS.

ContentRoot:  C:\MyApp\wwwroot
WebRoot:      C:\MyApp\wwwroot\wwwroot

Ici est de savoir comment nous en sommes ContentRoot et WebRoot.

public class Startup
{
    private readonly IHostingEnvironment _hostingEnv;

    public Startup(IHostingEnvironment hostingEnv)
    {
        _hostingEnv = hostingEnv;
    }

    public void Configure(IApplicationBuilder app)
    {
        app.Run(context =>
        {
            //test output
            context.Response.WriteAsync(_hostingEnv.ContentRootPath + "\r\n");
            return context.Response.WriteAsync(_hostingEnv.WebRootPath + "\r\n");
        });
    }

    public static void Main(string[] args)
    {
        var contentRoot = Directory.GetCurrentDirectory();
        var webRoot = Path.Combine(contentRoot, "wwwroot");

        var host = new WebHostBuilder()
            .UseKestrel()
            .UseIISPlatformHandlerUrl()
            .UseContentRoot(contentRoot)  //set content root
            .UseWebRoot(webRoot)          //set web root
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

De intellisense je vois que...

  • ContentRootPath contient le contenu de l'application fichiers.
  • WebRootPath contient le web-servable les fichiers de contenu.

Comment faire le test de sortie regarde plutôt comme ceci:

ContentRoot:  C:\MyApp\
WebRoot:      C:\MyApp\wwwroot\

OriginalL'auteur Shaun Luttin | 2016-04-14