剃刀网站不工作,所有dll都在场

时间:2013-10-18 13:18:59

标签: c# asp.net-mvc templates razor

我已将.cshtml网站上传到surftown服务器,我在运行代码时遇到了一些问题。但我在运行Razor代码时遇到问题。

这是页面呈现的方式:(Default.cshtml)enter image description here

我已经检查了内部通信问题。这是我的结果: enter image description here

但是为什么它不起作用,我该如何解决呢?

我听说这可能是观点的问题,但如果是这样的话我该如何解决?

我的网站文件夹树:(以及一些文件)

  • App_Code文件
  • 应用程序数据
      • Microsoft.AspNet.Razor.2.0.20710.0
      • Microsoft.Asp.Net.WebPages.2.0.20710.0
      • Microsoft.Asp.Net.WebPages.Administration.2.0.20710.0
      • Microsoft.Asp.Net.WebPages.Data.2.0.20710.0
      • Microsoft.Asp.Net.WebPages.WebData.2.0.20710.0
      • Microsoft.Web.Infrastructure.1.0.0.0
      • NuGet.Core.1.6.2
  • 箱子
    • jQuery.2.0.3
      • 内容
        • 脚本
      • 工具
    • Microsoft.AspNet.Mvc.4.0.30506.0
      • LIB
        • net40
    • Microsoft.AspNet.Razor.2.0.30506.0
      • LIB
        • net40
    • Microsoft.AspNet.WebPages.2.0.30506.0
      • LIB
        • net40
  • 网页
      • Read.cshtml
    • 编辑
      • 移动
        • Chapter.cshtml
      • Entry.cshtml
      • EnterEntry.cshtml
      • EnterNote.cshtml
    • 登录
      • Login.cshtml
    • 搜索
      • Result.cshtml
  • 脚本
    • 插件
      • TinyMCE的
  • 样式
    • CSS
  • 查看
    • _Layout.cshtml
  • Default.cshtml

我的web.config文件如下所示:

<?xml version="1.0"?>
    <configuration>
        <system.web>
            <compilation debug="true" targetFramework="4.0">
              <buildProviders>
                <add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
              </buildProviders>
              <assemblies>
                <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
              </assemblies>
            </compilation>
          </system.web>
          <connectionStrings>
            <add connectionString="database connection" providerName="System.Data.SqlClient"/>
          </connectionStrings>
        </configuration>

编辑: 问题是我的所有文件都是.cshtml吗?并将它们添加为MIME Type html/text

更多编辑: 这是我的Default.cshtml代码:

@{
    Layout = "~/Views/_Layout.cshtml";
}

<table>
    <tr>
        <td>
            <table>
                <tr>
                    <td>
                        <h1 class="header">
                            Welcome to the library
                        </h1>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p>
                            Do look around, to find information about almost anything there is to know about Mythodea, or maybe you are here to make a chapter or note of your own.
                        </p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

我的_Layout.cshtml代码:     @ {         //一堆C#代码     }

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />

    <link href="~/Styles/CSS/Layout.css" rel="stylesheet" />

    <script src="~/Scripts/Addons/TinyMCE/tinymce.min.js"></script>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

    @RenderSection("head",false)

    <title>The Kettle Library of Mythodea</title>
</head>
<body>
    <div id="container">
        <div id="header">
            <h1>
                The Library
            </h1>
        </div>

        <div id="left_column">
            <div class="innerPadding">
                <div id="Menu_Overview">
                    @Html.Raw(menu)
                </div>
            </div>
        </div>

        <div id="right_column">
            <div class="innerPadding">
                @{
                    if(!SessionHandler.UserIsLoggedIn)
                    {
                        <div class="Login_Wrapper">
                            <form action="" method="post">
                                <table>
                                    <tr>
                                        <td>
                                            <p>
                                                Username/Email:
                                            </p>
                                        </td>
                                        <td>
                                            <input class="form_input" type="text" placeholder="Username / Email" tabindex="1" name="username" value="@username" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p>
                                                Password:
                                            </p>
                                        </td>
                                        <td>
                                            <input class="form_input" type="password" placeholder="Password" tabindex="2" name="password" />
                                            <a href="#">forgot?</a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="submit" value="Login" name="btn" />
                                        </td>
                                        <td>
                                            <input type="submit" value="Register" name="btn" />
                                        </td>
                                    </tr>
                                </table>
                            </form>
                            <p class="Error_Message">@message_error</p>
                        </div>
                    }
                    else
                    {
                        <div class="Login_Wrapper">
                            <form action="" method="post">
                                <p>
                                    @name
                                </p>
                                <input type="submit" value="Logout" name="btn" />
                            </form>
                        </div>
                    }
                }

                <div class="SideMenu_Right">
                    <div id="search_wrapper">
                        <form action="" method="post">
                            <input type="text" name="searchField" placeholder="Search" value="@searchValue" required="required" />
                            <input type="submit" name="btn" value="Search" />
                        </form>
                    </div>

                    @{
                        if(SessionHandler.UserIsLoggedIn)
                        {
                            <a href="~/Pages/Entries/EnterEntry.cshtml">Create new Chapter</a>
                            <br />
                            <br />
                        }
                    }

                    @RenderSection("menu_right", false)
                </div>
            </div>
        </div>
        <div id="middle_column">
            <div class="innerPadding">
                @RenderBody()
            </div>
        </div>
    </div>
    <div id="madeBy">
        <p>
            Created by <a href="https://www.facebook.com/michaeltot.korsgaard" target="_blank">Michael Tot Korsgaard</a>
        </p>
    </div>
</body>
</html>

2 个答案:

答案 0 :(得分:4)

您似乎没有使用MVC架构。为什么使用Pages而不是Views 我已经看到了你所有的错误,而且每件事情都正常。以这种方式解决部署问题太难了。所以我在实际服务器上部署MVC应用程序的基本指令可能很有用:

  1. 确保您的应用程序在localhost和您身上正常运行 没有改变正常的应用程序或没有任何不需要的 错误的默认应用程序配置。
  2. 然后将所需的程序集引用添加到项目中 通过以下方式编译/运行其他MVC扩展,如razor: 右键单击您的项目 - &gt;添加可部署的依赖项 - &gt;标记 MVC&amp;剃刀 - &gt;行
  3. 然后再次右键单击您的项目 - &gt;构建部署包| 那么它就可以发布了。
  4. 然后通常尝试发布流程
  5. 到目前为止,您已经配置了使用Windows服务器的应用程序,虽然它不支持MVC技术,但您的应用程序具有相关的程序集引用以在服务器上运行/编译。现在所有事情都与服务器和IIS配置有关。请按照以下说明操作:

    1. THIS配置IIS。(如果您的主机支持此类型的 连接)
    2. 如果服务器是您的,请确保您没有异常 应用程序配置和根服务器配置相关 .net Framework。
    3. 修改

      关于MVC中的默认页面呈现,请考虑在 Global.asax 文件中我们设置默认路由,如bellow(通过调用RegisterRoutesRouteConfig类的函数):

      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
      
          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
      }
      

      在MVC架构中,我们不使用传统的ASP页面路由,例如使用 Default.cshtml 。 每个Controller根据其操作方法调用Views Folder中的同名文件夹并控制.cshtml子页面。没有选择可以重命名放置在应用程序上的Default View文件夹。 关于Mastering页面考虑默认情况下每个MVC应用程序在决定渲染视图时,首先调用位于根文件夹 _ViewStart.cshtml 文件,以了解母版页的名称是什么根据_ViewStart的内容。在此步骤到下一步,我们有主视图和部分视图概念。

      例如,如果您尝试更改_ViewStart.cshtml文件的名称(例如_Start.cshtml),您将在浏览器中看到以下页面:

      Error When changing _ViewStart.cshtml file name

      因此,在使用MVC架构时,您必须遵循一些规则/合同来构建成功的应用程序。

答案 1 :(得分:1)

您缺少来自Views / Pages文件夹的web.config

它应该是这样的:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>