I just create a new MVC 4 Web API project, and create a new .cshtml file, containing very simple HTML:
&
I had the same message in an MVC project and it turned out that I was missing a critical piece of the MVC framework, the Global.asax and Global.asax.cs entries. I selected the project in Solution Explorer and did an Add, New Item, Global Application Class. I then edited it and replaced the Application_Start with the necessary config items:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
This solved it for me.
UPDATE 2:
I have finally understood what you are trying to achieve. Sorry for me not understanding initially. I didn't read your question carefully enough. 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" />
It's 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.
ORIGINAL
You should not request directly a .cshtml
file in an ASP.NET MVC application. Those are views located in the ~/Views
folder. They are not directly accessible. You need a corresponding controller action.
For example let's say that you have the following controller:
public class HomeController: Controller
{
public ActionResult Index()
{
return View();
}
}
and then have defined the ~/Views/Home/Index.cshtml
view with the contents shown in your question.
Now when you run your application you could navigate to /Home/Index
which will execute the Index
action of the Home
controller and render the corresponding view.
I would recommend you reading some getting started tutorials about ASP.NET MVC in order to familiarize yourself with the basic most fundamental concepts.
UPDATE 1:
The code that blocks requests to .cshtml
files inside the ~/Views
folder is situated inside the ~/Views/web.config
file:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
If you have enabled Web Pages and you have verified that the .NET version is valid then your problem is most likely that the IIS server does not have the razor binaries available to be shared across all sites. To fix it you should ensure you've included the mvc binaries in your /bin folder. This link explains it very well:
http://www.codeproject.com/Answers/437259/his-type-of-page-is-not-served-CSHTML-how-to-serve#answer1
I had the same issue and I resolved it by going to the properties of the Client and where it says "Start Action", select current page. I had it set to specific page.