Apolymoxic
Apolymoxic

Reputation: 836

.CSHTML pages will not render

I am trying to get my server to run .cshtml files. Using WebMatrix 3 I can view the pages by right clicking and selecting "view in browser", but that views through a localmachine port. If I try to access the pages from the internet, I get a 500 error.

Here is what I have done:

I am suspecting it's something to do with my web.config file because if I remove the file, the page will show, but it reads like text. For example (in the most basic page I could think of):

@{
   var currentTime = dateTime.Now; 
}

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Testing</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    </head>
    <body>
        The current time is @currentTime .
    </body>
</html>

The page will render like:

@{ var currentTime = dateTime.Now;} The current time is @currentTime .

Yet, I am clueless as to what should or should not be in the web.config file. I have been wracking my brain over this for close to a month...

Here is what is in the web.config file:

<configuration>     

    <system.data>
        <DbProviderFactories>
            <remove invariant="System.Data.SqlServerCe.4.0" />
            <add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
    </system.data>
    <appSettings>
        <add key="webPages:Version" value="2.0"/>
        <add key="webpages:Enabled" value="true" />
    </appSettings>

    <system.webServer>
        <httpErrors errorMode="Detailed" />
    </system.webServer>

</configuration>

Many thanks in advance.

Upvotes: 4

Views: 7860

Answers (2)

Apolymoxic
Apolymoxic

Reputation: 836

It seems that I had an older version... this was answered here:

CSHTML rendering text only - static page?

Upvotes: 0

juhan_h
juhan_h

Reputation: 4011

If I understand you correctly you are having problems running this in IIS (Internet Information Services - the built in Web server on Windows). It looks like the directory you are serving is not configured as a Web Application (but it is configured as a Virtual Directory). To fix this:

  1. Open IIS manager (Win + R and copy %systemroot%\system32\inetsrv\iis.msc to the run window)
  2. Navigate to your directory in the tree on the left (probably \Sites\Default Web Site\something
  3. Right click on it and choose "Convert to Application"

These steps should make IIS at least try to render the .cshtml.

On a separate note .cshtml (ie ASP.NET MVC) is so much more easier to learn and understand than .asp (ie simply ASP.NET)

Upvotes: 0

Related Questions