带有虚拟目录/应用程序的ASP.NET 5 beta8应用程序

时间:2015-10-21 07:42:51

标签: asp.net-core iis-8

自ASP.NET 5 beta8以来,我们在使用虚拟目录和/或子应用程序时遇到了问题。

我们希望(在时间上)从虚拟目录或“子应用程序”提供图像。但是,我们在尝试使用虚拟目录时只会遇到404错误,而在使用“子应用程序”时会出现502.3错误。 服务器正在运行IIS 8.0。站点的应用程序池和“子应用程序”设置为“无管理代码”。

enter image description here

在运行我们网站的“旧”ASP.NET 4版本的另一个站点上使用相同的虚拟目录/应用程序配置,就像预期的那样。 问题出现在升级到beta8之后,所以我们假设它与HttpPlatformHandler有关。

我们是否遗漏了某些东西或者这是一个错误?

编辑: 为了澄清,ASP.NET5应用程序工作得很好。它只是来自虚拟目录/应用程序的内容无法访问。 HttpPlatformHandler安装在服务器上。

这是我们当前的Startup.cs

public class Startup
{
    public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(appEnv.ApplicationBasePath)
            .AddJsonFile("appsettings.json")
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

        builder.AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; set; }

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.ConfigureXXXXXXIdentityServices(); // Custom identity implementation

        services.AddMvc(options =>
        {
            options.OutputFormatters
                .Add(new JsonOutputFormatter(new JsonSerializerSettings
                { 
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }));
        });

        services.AddSqlServerCache(options =>
        {
            options.ConnectionString = "XXXXXX";
            options.SchemaName = "dbo";
            options.TableName = "AspNet5Sessions";
        });

        services.AddSession();

        var builder = new ContainerBuilder();
        builder.RegisterModule(new AutofacModule());
        builder.Populate(services);

        var container = builder.Build();

        return container.Resolve<IServiceProvider>();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.MinimumLevel = LogLevel.Debug;
        loggerFactory.AddConsole();
        loggerFactory.AddDebug();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();

            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString("/gfx"),
                FileProvider = new PhysicalFileProvider(@"\\webdata2.XXXXXX.se\webdata\gfx"),
                EnableDirectoryBrowsing = false
            });

            app.UseFileServer(new FileServerOptions
            {
                RequestPath = new PathString("/files"),
                FileProvider = new PhysicalFileProvider(@"\\webdata2.XXXXXX.se\webdata"),
                EnableDirectoryBrowsing = false
            });
        }
        else
        {
            app.UseExceptionHandler("/Error/Index");
        }

        app.UseIISPlatformHandler();

        app.UseStaticFiles();

        app.UseIdentity();

        app.UseSession();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

app.UseFileServer()语句适用于我们的开发机器,但不能在服务器上使用,除非有办法指定凭据。 (还没有办法做到这一点......(还......))

2 个答案:

答案 0 :(得分:2)

让它“有效”。

  • 删除了所有虚拟目录和/或应用程序。
  • 将应用程序池用户更改为有权读取另一台计算机上的文件共享的用户。
  • 为所需路径的所有环境添加了app.UseFileServer()

感觉应该有一个选项将网络凭据传递给UseFileServer方法......

答案 1 :(得分:0)

主机模型在测试版8中已更改,这意味着您需要以管理员身份安装新的HttpPlatformHandler模块。

请参阅Change to IIS hosting model