Backend/.NET

Using Static Files

Jin-Co 2023. 4. 19. 19:26
반응형

Static files are assets such as images that we need for our application. In .NET, to use such files, we need an additional set up and I will work you through necessary steps in this writing.

Creating a Project with DB

 

Relational DB - Getting Data including Data from Other Entities (Generic Repository Pattern)

Let's see how we can get data from a primary entity that has reference to other entities with the generic repository pattern Implementation Creating an Application How to create .NET web-API Setting up development tools When working with .NET, we need tool

jin-co.tistory.com

DTO (Manipulating Image Path)

 

Data Transfer Object (DTO)

The Data Transfer Object(DTO) is a container that transfers the API data between layers. Using this container, we can manipulate the data or change the structure of the data. Let's see how Creating a Project Relational DB - Getting Data including Data from

jin-co.tistory.com

Implementation

Adding an Asset Folder and Adding Assets

Create a folder called 'wwwroot' under the webapi project

wwwroot

Folders and files under the wwwroot folder are the path to be used to request the assets. Create a folder to store images and add an image for testing

Right click the image and copy the path. We need what comes after the '/wwwroot/' to specify the path

Adding Service

Go to the Program.cs file and add the code below right above 'app.UseAuthorization();'

app.UseStaticFiles();

Run

Move to the API folder

cd /API

And run the app

dotnet watch

Click the link (or copy and paste in the search bar)

 

Then it will show the image

In this writing, we have seen how we can use static files (assets).

 

728x90
반응형