software_writer
software_writer

Reputation: 4458

Serve static files from a folder inside wwwroot

I have following ASP.NET Core project structure:

.
├── Controllers
├── Dockerfile
├── Models
├── Program.cs
├── Properties
├── README.md
├── Services
├── Startup.cs
├── Views
├── appsettings.json
├── bundleconfig.json
├── project.json
├── web.config
└── wwwroot

Inside wwwroot, I have set up an Aurelia project using Aurelia cli. It has following structure:

.
├── aurelia-app
├── css
├── images
├── js
└── temp.html

and my aurelia-app has the index.html file which I want to serve(when I browse to localhost:5000, in a similar way if it was in wwwroot)

Here's what my Startup.cs configure() method looks like:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseBrowserLink();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
    }

    app.UseStaticFiles();

    app.UseFileServer(new FileServerOptions
    {
        EnableDefaultFiles = true,
        EnableDirectoryBrowsing = true,
    });

   app.UseMvc();
}

What should I change so that upon loading the base url, it looks for the index.html file in wwwroot/aurelia-app directory?

Upvotes: 0

Views: 2921

Answers (2)

Henk Mollema
Henk Mollema

Reputation: 46491

This has more to do with the default 'index' file of your website than with serving static files. I guess you want to serve all the files in wwwroot, not just what's inside wwwroot/aurelia-app. So scoping your static files middleware to wwwroot/aurelia-app won't work.

Your best option is probably to set the default application URL to http://localhost:5000/aurelia-app/index.html in your launchSettings.json (Project -> Properties -> launchSettings.json):

"iisExpress": {
  "applicationUrl": "http://localhost:5000/aurelia-app/index.html",
}

You should apply such setting in your IIS website or Azure Web App as well. For example: Azure Web App settings

Upvotes: 1

Mohsen Esmailpour
Mohsen Esmailpour

Reputation: 11544

I'm not sure this works or not, but you can try.

var options = new DefaultFilesOptions
{
   RequestPath = RequestPath = new PathString("/wwwroot/aurelia-app or /aurelia-app")
};
app.UseDefaultFiles(options);
app.UseStaticFiles();

Upvotes: 1

Related Questions