I just create a new MVC 4 Web API project, and create a new .cshtml file, containing very simple HTML:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title></title>
</head>
<body>
<div>
</div>
</body>
</html>
When opening the URL the following error displays:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /index.cshtml
I tested this scenario (exactly the same project) on a developing machine of one of my colleagues. It worked as expected. So I guess there must be something wrong with the configuration or some installation. But where to search? Neither local IIS nor Visual Studio Development Server works.
UPDATE
Accessing a .cshtml file directly isn't for production code - it's for training purposes, only!
Navigating to /Home/Index
works perfectly fine. So there is nothing else, which is obviously wrong. Just accessing .cshtml files directly.
You are trying to directly access a Razor page outside of the ~/Views
folder.
In ASP.NET MVC 4 this is disabled by default. In order to enable it all you have to do is adjust the following setting in your web.config:
<add key="webpages:Enabled" value="true" />
Its value is false
by default when you create a new ASP.NET MVC 4 project using any of the templates. So I guess your colleague already did this if you are saying that it works on his PC.