2015-11-19 9 views
6

Ich habe ein sehr einfaches eckiges App-Projekt, das nichts mehr tun muss, als statische Dateien von wwwroot zu bedienen. Hier ist meine Startup.cs:Serve static file index.html standardmäßig

public class Startup 
{ 
    public void ConfigureServices(IServiceCollection services) { } 

    public void Configure(IApplicationBuilder app) 
    { 
     app.UseIISPlatformHandler(); 
     app.UseStaticFiles(); 
    } 

    // Entry point for the application. 
    public static void Main(string[] args) => WebApplication.Run<Startup>(args); 
} 

Jedes Mal, wenn ich das Projekt mit IIS Express oder Web starten ich immer zu /index.html navigieren. Wie mache ich es so, dass ich einfach die Wurzel (/) besuchen kann und trotzdem index.html bekomme?

Antwort

5

einfach ändern app.UseStaticFiles(); zu app.UseFileServer();

public class Startup 
{ 
    public void ConfigureServices(IServiceCollection services) { } 

    public void Configure(IApplicationBuilder app) 
    { 
     app.UseIISPlatformHandler(); 
     app.UseFileServer(); 
    } 

    // Entry point for the application. 
    public static void Main(string[] args) => WebApplication.Run<Startup>(args); 
} 
5

Sie wollen Server-Standarddateien und statische Dateien:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
{ 
    ... 
    // Serve the default file, if present. 
    app.UseDefaultFiles(); 
    app.UseStaticFiles(); 
    ... 
} 

die documentation für weitere Informationen.

Verwandte Themen