Aspnetcore.docs: Upgrade static files sample to 2.x

Created on 6 Mar 2018  路  9Comments  路  Source: dotnet/AspNetCore.Docs

  1. Write a short paragraph describing what the topic will cover.

I'd like to ask for update of sample content available here:
https://github.com/aspnet/Docs/tree/master/aspnetcore/fundamentals/static-files/samples

to cover version 2.*.

The docs discussing the content in subject are here:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?tabs=aspnetcore2x

I've found that most of the content related to static, simple web site with dotnet are now outdated as they cover version 1.*, so it would be nice to have that sample upgraded.

Thanks!

Most helpful comment

@peterblazejewicz Yes, I see what you mean. Absolutely, yes! ...

Just start with an empty web starter template and add in the Static File Middleware as described in the topic.

That empty web starter project doesn't have MVC or Razor Pages bits ... it's just bare bones. It only writes a "Hello World!" out.

If you want to see the template for it in the GitHub repo, it's here :point_right: https://github.com/aspnet/templating/tree/dev/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp ... take a look at the Startup class, and you'll see what I mean.

If you want to generate that project locally, you can use Visual Studio and select the empty ASP.NET Core web starter template for a new project. If you're not using Visual Studio, run dotnet new web from a command prompt in an empty folder. If you want to see all of the templates it can create, type dotnet new --help. The doc is here :point_right: https://docs.microsoft.com/dotnet/core/tools/dotnet-new?tabs=netcore2x

Then, just add the Static File Middleware with app.UseStaticFiles(); to the Configure method as described in https://docs.microsoft.com/aspnet/core/fundamentals/static-files?tabs=aspnetcore2x.

We also have some nice content over in the Hosting topic ... especially the beginning, where it talks about creating a web host: https://docs.microsoft.com/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x ... that will help you understand what CreateDefaultBuilder in the Program class is setting up behind-the-scenes.

I'm going to note our discussion here over in the tracking issue. When that whole topic (and the sample) is updated, the author might be able to address your scenario by stating that Static File Middleware can be used independently of other middlewares, MVC, and Razor Pages.

All 9 comments

What in the document is out of date for 2.0?

Could probably call this a dup ... this one is on the tracking issue for update: https://github.com/aspnet/Docs/issues/5495 Yes, @peterblazejewicz, it's going to get the "full treatment" :smile: lol, including the updates for 2.1.

dup of #5495

Hi folks,
Sorry for late reply.
You're discussing docs. I read the docs and I know there are sections for 2.0/1.0 (maybe not yet for 2.1).
I've asked to update source file in this repo samples folder: Upgrade static files sample to 2.x
I could do this myself. The dup linked issue deals with .md files unless I'm wrong (that is directly discuss docs update)
Thanks!

@peterblazejewicz https://github.com/aspnet/Docs/issues/5495 deals with the sample updates, and this one is on the list. We're probably going to bypass taking it to 2.0 and roll in the 2.1 updates as well. Also, this sample isn't a Razor Pages sample, and it will likely become a Razor Pages app when it's upgraded.

@guardrex

this sample isn't a Razor Pages sample, and it will likely become a Razor Pages app when it's upgraded.

Can we keep the server simple and nimble? And be able to serve static content first - before using heavy gun like Razor pages. I'd like to be able to just setup a static page (say on single chip, $5 computer, just html hosting page and javascript for client application).
Thanks for the answer, appreciated!

@peterblazejewicz Yes, I see what you mean. Absolutely, yes! ...

Just start with an empty web starter template and add in the Static File Middleware as described in the topic.

That empty web starter project doesn't have MVC or Razor Pages bits ... it's just bare bones. It only writes a "Hello World!" out.

If you want to see the template for it in the GitHub repo, it's here :point_right: https://github.com/aspnet/templating/tree/dev/src/Microsoft.DotNet.Web.ProjectTemplates/content/EmptyWeb-CSharp ... take a look at the Startup class, and you'll see what I mean.

If you want to generate that project locally, you can use Visual Studio and select the empty ASP.NET Core web starter template for a new project. If you're not using Visual Studio, run dotnet new web from a command prompt in an empty folder. If you want to see all of the templates it can create, type dotnet new --help. The doc is here :point_right: https://docs.microsoft.com/dotnet/core/tools/dotnet-new?tabs=netcore2x

Then, just add the Static File Middleware with app.UseStaticFiles(); to the Configure method as described in https://docs.microsoft.com/aspnet/core/fundamentals/static-files?tabs=aspnetcore2x.

We also have some nice content over in the Hosting topic ... especially the beginning, where it talks about creating a web host: https://docs.microsoft.com/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x ... that will help you understand what CreateDefaultBuilder in the Program class is setting up behind-the-scenes.

I'm going to note our discussion here over in the tracking issue. When that whole topic (and the sample) is updated, the author might be able to address your scenario by stating that Static File Middleware can be used independently of other middlewares, MVC, and Razor Pages.

Awesome, that's really helpful!

Sure thing ... glad I could help. If you need to chat with devs about ASP.NET Core, many devs hang out on the ASP.NET Core Slack channel. The self-signup is here: http://tattoocoder.com/aspnet-slack-sign-up/ ... and there are many channels that pertain to specific areas of ASP.NET Core, but you can ask just about anything in the #general or #aspnet-core chat rooms.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaron-bozit picture aaron-bozit  路  3Comments

Rick-Anderson picture Rick-Anderson  路  3Comments

wgutierrezr picture wgutierrezr  路  3Comments

nenmyx picture nenmyx  路  3Comments

AnthonyMastrean picture AnthonyMastrean  路  3Comments