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>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…