1
namespace MyQuotesApp
{
    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)
        {
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseDefaultFiles();
            app.UseStaticFiles();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});

            app.UseMvc();
        }
    }
}
3
  • what is the name of your default file ? Commented Jan 24, 2017 at 6:01
  • Upgrade you packages if it not targeting to latest one 1.1 ? Commented Jan 24, 2017 at 6:06
  • default file name is index.html in wwwrool folder and upgrade all packeges...but not work Commented Jan 25, 2017 at 2:03

2 Answers 2

6

UseDefaultFiles pick these files by default.

  • default.htm
  • default.html
  • index.htm
  • index.html

If that not worked in your case. You can specify name of your default file with DefaultFilesOptions.

DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(options);

You can also use app.UseFileServer();, it combines the functionality of

app.UseDefaultFiles();
app.UseStaticFiles();

Note: UseDefaultFiles must be called before UseStaticFiles to serve the default file. UseDefaultFiles is a URL re-writer that doesn't actually serve the file. You must enable the static file middleware (UseStaticFiles) to serve the file.

P.S. also update your packages to most latest.

Sign up to request clarification or add additional context in comments.

1 Comment

This actually helped me, wouldn't have figured out that my problem was the order of defaultfiles and staticfiles alone... Or would, after a lot of pain. Thanks.
0

Try this.

app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                     template: "{controller=*YourControllerName*}/{action=Index}/{id?}"
                );
            });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.