Pra*_*han 1 angularjs asp.net-core-mvc asp.net-core
namespace MyQuotesApp
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
//app.Run(async (context) =>
//{
// await context.Response.WriteAsync("Hello World!");
//});
app.UseMvc();
}
}
}
Run Code Online (Sandbox Code Playgroud)
UseDefaultFiles默认选择这些文件。
如果这对你的情况不起作用。您可以使用 指定默认文件的名称DefaultFilesOptions。
DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(options);
Run Code Online (Sandbox Code Playgroud)
您还可以使用app.UseFileServer();,它结合了以下功能
app.UseDefaultFiles();
app.UseStaticFiles();
Run Code Online (Sandbox Code Playgroud)
注意: 必须在提供默认文件UseDefaultFiles之前调用。是一个 URL 重写器,实际上并不提供文件服务。您必须启用静态文件中间件 ( ) 才能提供该文件。UseStaticFilesUseDefaultFilesUseStaticFiles
PS还将您的软件包更新到最新。
| 归档时间: |
|
| 查看次数: |
821 次 |
| 最近记录: |