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();
}
}
}
-
what is the name of your default file ?Ahmar– Ahmar2017-01-24 06:01:01 +00:00Commented Jan 24, 2017 at 6:01
-
Upgrade you packages if it not targeting to latest one 1.1 ?Ahmar– Ahmar2017-01-24 06:06:42 +00:00Commented Jan 24, 2017 at 6:06
-
default file name is index.html in wwwrool folder and upgrade all packeges...but not workPraful Chauhan– Praful Chauhan2017-01-25 02:03:37 +00:00Commented Jan 25, 2017 at 2:03
Add a comment
|
2 Answers
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.
1 Comment
Felype
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.