[英]Serve static files from a folder inside wwwroot
I have following ASP.NET Core project structure: 我有以下ASP.NET Core项目结构:
.
├── Controllers
├── Dockerfile
├── Models
├── Program.cs
├── Properties
├── README.md
├── Services
├── Startup.cs
├── Views
├── appsettings.json
├── bundleconfig.json
├── project.json
├── web.config
└── wwwroot
Inside wwwroot
, I have set up an Aurelia project using Aurelia cli
. 在wwwroot
内部,我使用Aurelia cli
建立了一个Aurelia项目。 It has following structure: 它具有以下结构:
.
├── aurelia-app
├── css
├── images
├── js
└── temp.html
and my aurelia-app
has the index.html
file which I want to serve(when I browse to localhost:5000
, in a similar way if it was in wwwroot
) 我的aurelia-app
具有要服务的index.html
文件(当我浏览到localhost:5000
,如果它位于wwwroot
,则以类似的方式)
Here's what my Startup.cs
configure() method looks like: 这是我的Startup.cs
configure()方法的样子:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions
{
EnableDefaultFiles = true,
EnableDirectoryBrowsing = true,
});
app.UseMvc();
}
What should I change so that upon loading the base url, it looks for the index.html
file in wwwroot/aurelia-app
directory? 我应该更改什么,以便在加载基本URL时在wwwroot/aurelia-app
目录中查找index.html
文件?
I'm not sure this works or not, but you can try. 我不确定这是否可行,但您可以尝试。
var options = new DefaultFilesOptions
{
RequestPath = RequestPath = new PathString("/wwwroot/aurelia-app or /aurelia-app")
};
app.UseDefaultFiles(options);
app.UseStaticFiles();
This has more to do with the default 'index' file of your website than with serving static files. 这与网站的默认“索引”文件有关,而不是与提供静态文件有关。 I guess you want to serve all the files in wwwroot
, not just what's inside wwwroot/aurelia-app
. 我想您想提供wwwroot
所有文件,而不仅仅是wwwroot/aurelia-app
内部的文件。 So scoping your static files middleware to wwwroot/aurelia-app
won't work. 因此,将静态文件中间件限定为wwwroot/aurelia-app
无效。
Your best option is probably to set the default application URL to http://localhost:5000/aurelia-app/index.html
in your launchSettings.json
(Project -> Properties -> launchSettings.json): 最好的选择可能是在launchSettings.json
(项目->属性-> launchSettings.json)中将默认应用程序URL设置为http://localhost:5000/aurelia-app/index.html
:
"iisExpress": {
"applicationUrl": "http://localhost:5000/aurelia-app/index.html",
}
You should apply such setting in your IIS website or Azure Web App as well. 您也应该在IIS网站或Azure Web App中应用此类设置。 For example: 例如:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.