How do you request static .html files under the ~/Views folder in ASP.NET MVC?

alex.mironov picture alex.mironov · Jul 30, 2013 · Viewed 87.1k times · Source

I want to be able to request static .html files which are located in the ~/Views folder. According to the documentation, the routing system checks to see if a URL matches a disk file before evaluating the application's routes.

But when I request the file a 404 error arises.

My file is located in ~/Views folder. The URL is: http://[localhost]/Views/HtmlPage1.html

What have I missed?

Answer

Darin Dimitrov picture Darin Dimitrov · Jul 30, 2013

I want to be able to request static .html files which are located in the '~/Views' folder.

You can't. There's a web.config file in this folder which explicitly forbids accessing any file from it. If you want to be able to access files from the client those files should not be placed in the Views folder which has a special meaning in ASP.NET MVC.

You could have a ~/Static folder where you could place your HTML files. And then access it like that:

http://example.com/yourapplicationname/static/foo.html