jovnas
jovnas

Reputation: 394

ASP.NET 5 beta8 app with virtual directories/applications

Since ASP.NET 5 beta8 we are experiencing problems using virtual directories and/or sub applications.

We want (for the time beeing) to serve images from a virtual directory or a "sub application". However we only get 404 errors when trying to use a virtual directory and 502.3 errors when using a "sub application". The server is running IIS 8.0. The Application Pools for the site and the "sub application" is set to "No Managed Code".

enter image description here

Using the same configuration of virtual dirs/apps on another site running the "old" ASP.NET 4 version of our site works like expected. The problem came after upgrading to beta8, so we assume it has something to do with the HttpPlatformHandler.

Are we missing something or is this a bug?

EDIT: To clarify, the ASP.NET5 application works just fine. It is only the content from the virtual dirs/apps that cannot be accessed. The HttpPlatformHandler is installed on the server.

Here is our current 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?}");
        });
    }
}

The app.UseFileServer() statements works on our dev machines, but cannot be used on the server, unless there is a way to specify credentials. (haven't found a way to do that... (yet...))

Upvotes: 3

Views: 757

Answers (2)

jovnas
jovnas

Reputation: 394

Got it "working".

  • Dropped all virtual directories and/or applications.
  • Changed the Application Pool user to a user that had rights to read the file shares on the other machine.
  • Added app.UseFileServer() to all environments for the required paths.

Feels like there should be an option to pass Network Credentials to the UseFileServer method...

Upvotes: 2

Leonardo Herrera
Leonardo Herrera

Reputation: 8406

The Hosting model changed in beta 8, meaning that you need to install the new HttpPlatformHandler module as an administrator.

See Change to IIS hosting model

Upvotes: 0

Related Questions