我们如何设置ContentRootPath和WebRootPath? [英] How do we set ContentRootPath and WebRootPath?
本文介绍了我们如何设置ContentRootPath和WebRootPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从IIS运行应用程序时,我们将获得以下ContentRoot和WebRoot.
We're ending up with the following ContentRoot and WebRoot when we run our app from IIS.
ContentRoot: C:\MyApp\wwwroot
WebRoot: C:\MyApp\wwwroot\wwwroot
这是我们设置 ContentRoot
和 WebRoot
的方式.
Here is how we are setting ContentRoot
and 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();
}
}
从智能感知中我看到了...
From intellisense I see that...
- ContentRootPath 包含应用程序内容文件.
- WebRootPath 包含可在网络上投放的内容文件.
- ContentRootPath contains the application content files.
- WebRootPath contains the web-servable content files.
我们如何使测试输出看起来像这样:
How do we make the test output look instead like this:
ContentRoot: C:\MyApp\
WebRoot: C:\MyApp\wwwroot\
推荐答案
在RC2中,如果将 web.config
放在 wwwroot
旁边,并将IIS指向像这样的> MyApp
目录...
In RC2, if we put the web.config
beside wwwroot
and point IIS at the MyApp
directory like this...
MyApp
web.config
wwwroot
...原始问题中的代码将输出此内容...
...the code from the original question outputs this...
ContentRoot: C:\MyApp\
WebRoot: C:\MyApp\wwwroot\
这篇关于我们如何设置ContentRootPath和WebRootPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文