How to Access Static Content/Files in MVC Application?






4.78/5 (4 votes)
To access static files directly in MVC, we need to use different methods.
Introduction
This tip will provide you different methods to access the static content in MVC project.
Solution
In an MVC application, we want to access static files like some static Html pages or images.
Example: We have some static files like “AboutUs.html”, “Map.jpg”.
Method 1
To solve this, we need to make changes in Route.Config file to ignore those extension files.
routes.IgnoreRoute("{fileName}.jpg");
routes.IgnoreRoute("{fileName}.html");
Method 2
Add a folder named “Static” at the root of tour application and put all your static files there.
Now, you can access all the files from this folder directly without any issue.
Result:
Thanks for reading!