我正在使用Razor格式引擎創建基於ServiceStack的網站。在我的項目的文件夾根目錄我有「default.cshtml」,而是試圖導航到URL(localhost上)我收到一個302重定向到default.cshtml和以下頁面:ServiceStack Razor - 默認文檔「禁止」錯誤
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>
爲什麼不能剃刀引擎拿起我的默認內容頁?
您的[?debug = requestinfo](https://github.com/ServiceStack/ServiceStack/wiki/Debugging#request-info)頁面上是否有任何啓動錯誤? – mythz
哇 - 我怎麼會錯過這個選項!?我得到:「無法加載文件或程序集'System.Web.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = e06fbc6124f57c43'或其依賴項之一。」我正在運行VS2012,只是使用NuGet來安裝ServiceStack.Razor。 – jklemmack
好的,在這種情況下,它會是[ASP.NET WebPages依賴項問題](http://stackoverflow.com/a/22671119/85785)。 – mythz