繁体   English   中英

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

[英]Can not access virtual directory under virtual dotnet core api application on IIS 8

我试图将虚拟目录添加到我的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文件夹,该/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<RouteOptions>(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<IHttpContextAccessor, HttpContextAccessor>();
        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<ApiSettings>(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(<<your physical path>>), RequestPath = new PathString("/V1"), EnableDirectoryBrowsing = true // you make this true or false. }); 

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM