aspnet / StaticFiles

[Archived] Middleware for handling requests for file system resources including files and directories. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
114 stars 72 forks source link

404 status code not returned correctly #165

Closed ghost closed 7 years ago

ghost commented 7 years ago
    public void Configure(IApplicationBuilder application, ILoggerFactory loggers)
    {
        loggers.AddProviders();
        application.UseSession();
        application.UseStaticFiles();
        application.UseMvc(builder => builder.MapRoutes());
    }

If the "favicon.ico" file NOT exists, status code 404 is not returned, but it goes through routing middleware and then returned "200" status code. Should i check in my routing middleware again for static files.

Tratcher commented 7 years ago

By design. StaticFiles will serve existing files or else it will pass through because it cannot be sure if a given url was for a missing file or for another endpoint.

Why did you have a route that matched favicon.ico?

ghost commented 7 years ago

My routing middleware will handle all path. because I'm designing a multilingual site. "/Home/404a/404b...." will redirect to "/Missing" (en-US) "/首页/404a/404b...." will redirect to "/丢失" (zh-Hans) missing static files now redirect to "/Missing"

By design. StaticFiles will serve existing files or else it will pass through

This is OK. I'll modify my routing middleware a bit to ignore static files.