2016-03-03 21 views
33

Tôi đã tạo ra một trống Application Web trong NET Core, trong wwwroot Tôi có index.html mà không tải là trang mặc định, nó chỉ nạp khi tôi gọi nó là một cách rõ ràng.index.html không hiển thị trang mặc định

Đây là project.json tôi

{ 
    "version": "1.0.0-*", 
    "compilationOptions": { 
    "emitEntryPoint": true 
    }, 

    "dependencies": { 
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", 
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final" 
    }, 

    "commands": { 
    "web": "Microsoft.AspNet.Server.Kestrel" 
    }, 

    "frameworks": { 
    "dnxcore50": { } 
    }, 

    "exclude": [ 
    "wwwroot", 
    "node_modules" 
    ], 
    "publishExclude": [ 
    "**.user", 
    "**.vspscc" 
    ] 
} 

Đây Startup của tôi:

public class Startup 
{ 
    // This method gets called by the runtime. Use this method to add services to the container. 
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 
    public void ConfigureServices(IServiceCollection services) 
    { 
    } 

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
    public void Configure(IApplicationBuilder app) 
    { 
     app.UseStaticFiles(); 
    } 

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

Trả lời

74

Bạn phải thêm

app.UseDefaultFiles(); 

trước app.UseStaticFiles(); trong Configure phương pháp.

Xem documentation để biết thêm chi tiết.

+0

Tốt nhất! Bạn đúng rồi. Nó hoạt động và thứ tự đóng một vai trò lớn, những gì tôi không thích, nhưng ... – DAG

+3

Đây là thông tin bổ sung. Ví dụ thư viện nào cần thêm và thứ tự nào. http://www.talkingdotnet.com/make-index-html-startup-file-in-aspnet-core/ –

+0

Có một trang mà chúng ta có thể thấy, phần mềm trung gian nào phải được gọi khi nào? Hoặc, chỉ cần google tất cả ... – Legends

-5

Một cách khác để làm điều đó là chỉnh sửa tệp web.config của bạn. Thêm các quy tắc mới, tương ứng với nhu cầu của bạn.

Các vấn đề liên quan