I am trying to setup intranet IIS 8.5 (Win8.1) to globally serve .cshtml
(Razor) files. The corresponding Application Pool is set to v4.0
.
The files are simple Web Pages, not MVC. Here is an example of one:
<html>
<body>
@foreach (var i = 0; i < 10; i++)
{
<li>Item @i</li>
}
</body>
</html>
By removing the mapping of .cshtml
files to System.Web.ForbiddenHandler
on the IIS server's Handler Mappings I was able to get past the initial hurdle of ASP.NET telling me that
This type of file is not served.
However, the .cshtml
files are now served verbatim to the browser, instead of being run through the Razor rendering process.
One would think that it should be easy to serve Razor pages from IIS, but it isn't. I need to somehow convince IIS to interpret these pages as Razor views; I suspect I am missing some mapping to the appropriate handler (I don't want MVC though - just simple Web Pages).
Here are some additional constraints:
I would definitely like to avoid including a
bin
folder with the requisite Razor assemblies in each of the sites on the server. The server hosts many sites, and I don't want to have to copy thebin
folder everywhere. It should be possible to configure it globally, once and for all.Ideally, I would not even need a local
web.config
for each site. The sites that are being served are a patchwork of technologies, containing.html
,.shtml
,.php
,.asp
,.aspx
, and - hopefully -.cshtml
files and should not be dependent on a single technology or config.Creating a Visual Studio project is expressly out of the question. I should be able to use any text editor to modify the
.cshtml
files..NET Core is not installed on the machine and is not an option. Must use full Framework up to 4.6.2.
I am aware of many other SO questions that are similar, but don't quite solve my problem.
This question for example, was closed as "unclear" before it could have been answered, yet it was pretty clear to me! I am having the exact same problem.
The accepted answer to this question simply resorts to copying the bin folder. This is something I specifically don't want to do.
This answer says you can run an MVC application without installing MVC on your server, again by copying a bin
folder into the local root. I do want to install Razor (but not necessarily MVC) onto my server globally.
Essentially, what I am trying to do is to use Razor syntax in a way reminiscent of classic ASP, or ASPX, without the baggage of MVC.
Can it be done?