Welcome to the ASP .NET Tutorial on the wwwroot Folder! Let's dive into understanding this essential part of your ASP .NET project structure.
The wwwroot folder is a crucial directory in an ASP .NET project. It serves as the root for static files like CSS, JavaScript, images, and HTML pages.
The wwwroot folder's purpose is to host static files that will be directly served to the client without any server-side processing.
Here's a brief look at the structure of the wwwroot folder:
wwwroot/
ā
āāā css/
āāā fonts/
āāā img/
āāā js/
āāā index.html
Each of these directories (css, fonts, img, js) stores static files related to their respective types. The index.html file is the entry point for your web application when a user visits the root URL.
You can access the wwwroot folder by navigating to the project's root directory in the File Explorer or by using the Kestrel Server's default URL:
http://localhost:5000
Since the wwwroot folder contains static files, you can directly access them from the browser by appending the filename to your application's base URL.
Example: If you have an image named logo.png inside the wwwroot/img directory, you can access it at http://localhost:5000/img/logo.png.
Let's create a simple example by adding an HTML file and a CSS file in the wwwroot folder.
Create a new folder named styles inside the wwwroot folder.
Inside the styles folder, create a new CSS file named styles.css. Add some basic styling:
/* wwwroot/styles/styles.css */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}wwwroot folder, create a new HTML file named index.html. Add the following content:<!-- wwwroot/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/styles/styles.css">
<title>My ASP .NET App</title>
</head>
<body>
<h1>Welcome to my ASP .NET App!</h1>
</body>
</html>Where are static files served directly from in an ASP .NET project?
By now, you have a good understanding of the wwwroot folder in ASP .NET. In the next lesson, we'll explore more about the project structure and learn how to work with Razor Pages. Stay tuned!