Join Jess Chadwick for an in-depth discussion in this video Serving static content, part of ASP.NET Core: Razor Pages.
- [Instructor] Now that I'm using Razor Pages to serve HTML to the browser, it's time to make that HTML look good by serving some other static content as well such as CSS, web fonts, and images. Though the empty web application template does not enable it by default, ASP Net Core, provides great support for serving static content, and it's as simple as registering the static file middleware in the applications startup configuration.
To do this, simply add the line, app.UseStaticFiles right above the UseMvc call in the configure method. With the static files middleware in place, ASP Net Core will now look in the www root folder of your site for static files and return them if the file name matches the request. All we need now is some static files to serve. Luckily I've got some CSS and other content in the exercise files.
Just copy the contents of the www root folder under this video's artifacts folder to the www root folder of the website. Then, I can link to these files with a regular relative path. And, once that's in place, I can refresh the browser to see this new, beautiful style sheet in action.
- Creating a new application
- Setting up pages
- Rendering dynamic content
- Reusing markup with layouts
- Increasing the maintainability of pages
- Processing data
- Validating input
- Securing an application