ServiceStack Razor - “禁止"默认文档错误 [英] ServiceStack Razor - "Forbidden" error for default document

查看:42
本文介绍了ServiceStack Razor - “禁止"默认文档错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating a ServiceStack based website using the Razor format engine. In the folder root of my project I have "default.cshtml", but attempting to navigate to the URL (on localhost) I receive a 302 redirect to default.cshtml and the following page:

<代码>禁止的Request.HttpMethod: GETRequest.PathInfo:/default.cshtmlRequest.QueryString:Request.RawUrl:/default.cshtml

这是我的 Global.asax.cs:

Here is my 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:

And my 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:

And of course the default.cshtml:

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

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

Why can't the Razor engine pick up my default content page?

推荐答案

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

This ultimately appears to be some bad cached DLL or setting. Steps to resolve:

  • 通过将 ?debug=requestinfo 附加到 URL 来分析显示禁止"的页面上的调试信息.这是ServiceStack 在线文档中描述的一个方便的工具.
  • 停止 IIS Express 并关闭 Visual Studio.
  • 通过删除C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  • 的内容来清除临时ASP.Net文件
  • 已删除 &重新安装了两个有问题的 NuGet 包,Microsoft.AspNet.WebPagesServiceStack.Razor.
  • 清洁&重建,幸福.
  • Analyzed debug information on the page displaying "Forbidden" by appending ?debug=requestinfo to the URL. This is a handy tool described in the ServiceStack online docs.
  • Stopped IIS Express and shutdown Visual Studio.
  • Cleared temporary ASP.Net files by deleting the contents of C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  • Removed & reinstalled the two offending NuGet packages, Microsoft.AspNet.WebPages and ServiceStack.Razor.
  • Cleaned & rebuilt, and happiness.

这篇关于ServiceStack Razor - “禁止"默认文档错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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