【问题标题】:Static file on AzureAzure 上的静态文件
【发布时间】:2020-01-23 19:42:15
【问题描述】:

我只是通过 dotnet cli 创建了一个默认的 webapi 应用程序。 然后我添加了一个带有简单静态 index.html 文件的 wwwroot 文件夹。 然后我添加了以下两行代码:

app.UseDefaultFiles();
app.UseStaticFiles();

应用程序在本地按预期工作。 但是,如果我运行dotnet publish -c Release,然后通过 FTP 复制 Azure WebApp 上的输出, 未提供静态文件 (index.html)。 API 有效,但 wwwroot 中的静态文件无效。 我使用的是 P1V2 Azure 机器(付费)。

这是自动生成的 webconfig:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
<system.webServer>
  <handlers>
    <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
  </handlers>
  <aspNetCore processPath="dotnet" arguments=".\zz.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>

这是 Startup.cs:

namespace zz
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

非常感谢

【问题讨论】:

    标签: c# azure .net-core


    【解决方案1】:

    添加.UseWebRoot("wwwroot") 就可以了!

    【讨论】:

      猜你喜欢
      • 2018-12-01
      • 1970-01-01
      • 2015-10-30
      • 2019-06-30
      • 1970-01-01
      • 2021-12-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多