为什么无法访问静态文件?

时间:2019-12-23 16:46:52

标签: asp.net-core

我正在使用.net核心Web API。当我尝试访问位于wwwroot内的usersImages文件夹时,出现错误404。 enter image description here

在启动类中,我使用:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          app.UseStaticFiles();
          app.UseCors(options =>
          {
              options.AllowAnyOrigin()
                      .AllowAnyMethod()
                      .AllowAnyHeader();
          });        
          app.UseAuthentication();
          app.UseMvc();
      } 



1 个答案:

答案 0 :(得分:1)

您的Configure方法看起来正确,但我只是意识到您的图片网址看起来不正确。

您正在使用以下网址请求图片:localhost:63040/api/userImages/userid.jpg

我相信您的wwwroot文件夹下没有api文件夹。假设您的图像位于wwwroot> userImages> userid.jpg下。因此,您的网址应为:localhost:63040/userImages/userid.jpg

相关问题