ServiceStack Razor - 默认文档的“禁止”错误

时间:2014-03-27 22:21:43

标签: c# razor servicestack

我正在使用Razor格式引擎创建一个基于ServiceStack的网站。在我的项目的文件夹根目录中,我有“default.cshtml”,但是尝试导航到URL(在localhost上)我收到302重定向到default.cshtml和以下页面:

Forbidden Request.HttpMethod: GET Request.PathInfo: /default.cshtml Request.QueryString: Request.RawUrl: /default.cshtml

这是我的Global.asax.cs:

public class AppHost : AppHostBase
{
    public AppHost() : base("OOMS 2.0", typeof(OOMS.ServiceInterface.OOMSService).Assembly) { }

    public override void Configure(Container container)
    {
        Plugins.Add(new RazorFormat());
        Plugins.Add(new RequestLogsFeature());
    }
}

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        new AppHost().Init();
    }
}

我的web.config:

                                            

<appSettings>

  <add key="ResetAllOnStartUp" value="True" />
  <add key="webPages:Enabled" value="false" />
</appSettings>

<connectionStrings>

</connectionStrings>

<system.web>
  <compilation targetFramework="4.5" debug="true">


    <assemblies>
      <add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
    <buildProviders>
      <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" />
    </buildProviders>
  </compilation>
  <pages controlRenderingCompatibilityVersion="4.0" />
</system.web>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
  <handlers>
    <!-- IIS7 -->
    <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
  </handlers>
</system.webServer>
<system.web.webPages.razor>
  <!--<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />-->
  <pages pageBaseType="ServiceStack.Razor.ViewPage">
    <namespaces>
      <add namespace="ServiceStack" />
      <add namespace="ServiceStack.Html" />
      <add namespace="ServiceStack.Razor" />
      <add namespace="ServiceStack.Text" />
      <add namespace="ServiceStack.OrmLite" />
      <add namespace="OOMS.Web" />
    </namespaces>
  </pages>

  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc" />
</system.web.webPages.razor>

当然还有default.cshtml:

@{
}
<!doctype html>
<html lang="en-us">
    <body>
        Hello world
    </body>
</html>

为什么Razor引擎无法获取我的默认内容页面?

1 个答案:

答案 0 :(得分:5)

这最终似乎是一些错误的缓存DLL或设置。解决的步骤:

  • 通过将?debug=requestinfo附加到网址,在显示“禁止访问”的页面上分析调试信息。这是ServiceStack online docs
  • 中描述的方便工具
  • 停止IIS Express并关闭Visual Studio。
  • 删除C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  • 的内容,清除临时ASP.Net文件
  • 删除&amp;重新安装了两个有问题的NuGet软件包,Microsoft.AspNet.WebPagesServiceStack.Razor
  • 清洁&amp;重建,幸福。