.CSHTML页面将无法呈现 [英] .CSHTML pages will not render

查看:74
本文介绍了.CSHTML页面将无法呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的服务器运行.cshtml文件.使用WebMatrix 3,我可以通过右键单击并选择在浏览器中查看"来查看页面,但是可以通过本地计算机端口进行查看.如果尝试从Internet访问页面,则会出现500错误.

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:

  • 我确保已安装MVC 3(但我一直在阅读.cshtml不需要MVC ...还是可以确定的.
  • 我做了整个还原为父"/还原为继承"的事情,这在许多博客中都可以找到.
  • 一段时间以来我遇到404错误,因此我在.cshtml扩展名中添加了"text/html"的MIME类型.那解决了那个问题,但是只导致了我的500错误.

我怀疑这与我的web.config文件有关,因为如果删除该文件,则会显示该页面,但其读取内容类似于文本.例如(在我能想到的最基本的页面中):

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>

页面将呈现为:

@ {var currentTime = dateTime.Now;} 当前时间是 @currentTime .

但是,我对web.config文件中应该包含或不应该包含的内容一无所知.近一个月来,我一直在为此绞尽脑汁...

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...

这是web.config文件中的内容:

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>

非常感谢.

推荐答案

似乎我有一个较旧的版本...在这里得到了答案:

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

仅CSHTML呈现文本-静态页面?

这篇关于.CSHTML页面将无法呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆