Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Access Static Content/Files in MVC Application?

0.00/5 (No votes)
28 Feb 2016 4  
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!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here