无法访问IIS 8上虚拟dotnet核心api应用程序下的虚拟目录

我正在尝试将虚拟目录添加到我的dotnet核心API。 但它给了我一个404。

This api.project.nl page can't be found No web page was found for the web address: https://api.project.nl/v1/uploads/profiles/profile.jpeg 

我已经在主IIS网站下将我的api设置为v1 ,如下面的IIS项目配置中所示。 api工作正常,我甚至可以访问我的wwwroot/docs文件夹,它提供index.html (用于自定义swagger ui文档)。

在此处输入图像描述

可以访问Projects - Api文件夹下的uploads文件夹

 https://api.project.nl/uploads/profiles/profile.jpeg 

但它无法访问v1虚拟应用程序下的uploads文件夹。

 https://api.project.nl/v1/uploads/profiles/profile.jpeg 

知道为什么吗? 我不确定它是否可能,会对这方面的一些指示表示赞赏。 我已经看到了一些相关的问题,例如这里,但我的配置只是更进一步。 他们谈论UseFileServer ( 文档和他们让它使用它,但我似乎无法让它工作所有。不确定我需要它。

不确定是否需要,但这是我的StartUp.cs

  public class Startup { public IConfigurationRoot Configuration { get; } public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); builder.AddEnvironmentVariables(); Configuration = builder.Build(); } // This method gets called by the runtime. Use this method to add services to the container public void ConfigureServices(IServiceCollection services) { services.Configure(options => options.LowercaseUrls = true); services.ConfigureSwaggerGen(options => { options.SingleApiVersion(new Info { Version = "v1", Title = "Project Web Api Docs", TermsOfService = "None", Contact = new Contact { Name = "-", Email = "-", Url = "https://project.nl" } }); }); services.AddMvc(config => { // add policy for a global '[Authorize]' attribute filter, // so it doesn't have to be placed on all controllers var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); config.Filters.Add(new AuthorizeFilter(policy)); }); // Configure rollbar error reporting services.AddSingleton(); services.AddRollbarWeb(Configuration); services.AddSingleton(Configuration); // inject an implementation of ISwaggerProvider with defaulted settings applied services.AddSwaggerGen(); services.AddOptions(); // Inject the api settings services.Configure(Configuration.GetSection("ApiSettings")); // Configure mappings Mappings.ConfigureMappings(); } // 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(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // Configure CORS settings app.UseCors(builder => builder.WithOrigins("http://localhost:9000", "http://localhost:8100", "https://connect.project.nl") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() ); // Configure rollbar app.UseRollbarExceptionHandler(); app.UseJwtBearerAuthentication(new JwtBearerOptions { Audience = Configuration["ApiSettings:Auth0:ClientId"], Authority = $"https://{Configuration["ApiSettings:Auth0:Domain"]}/" }); app.UseMvc(); // enable static files, for the wwwroot (and accompanying docs in it) // also enable 'default files', such as default.htm, index.html etc. app.UseDefaultFiles(); app.UseStaticFiles(); // enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(routeTemplate: "docs/{apiVersion}/swagger.json"); } } 

我同意@Tseng但我会添加以下内容。

  1. ASP.net核心是针对多平台构建的,因此它不会处理某些请求或管理其他操作系统中的IIS等虚拟目录或应用程序。 在您的情况下,V1是主应用程序中的应用程序

  2. 如果你必须做任何这样的事情,那么你做了以下事情。

     app.UseFileServer(new FileServerOptions() { FileProvider = new PhysicalFileProvider(<>), RequestPath = new PathString("/V1"), EnableDirectoryBrowsing = true // you make this true or false. }); 

完成此配置后,无需在IIS中进行配置。