0

我已经设置了带有几个视图的 Service Stack Web 项目。我可以/Default.cshtml毫无问题地访问视图,但是当我尝试访问/Views/文件夹中的任何内容时,出现以下错误:

Forbidden

Request.HttpMethod: GET
Request.PathInfo: /Views/MyView.cshtml
Request.QueryString: 
Request.RawUrl: /Views/MyView.cshtml

我已经查看了herehere以及许多其他答案,但我似乎无法弄清楚这一点。

这是我的看法:

@{
    ViewBag.Title = "Fake View";
}

<div>
    <div>Hello!</div>
</div>

还有我的 Web.Config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <configSections>

        <sectionGroup name="jsEngineSwitcher">
            <section name="core" type="JavaScriptEngineSwitcher.Core.Configuration.CoreConfiguration, JavaScriptEngineSwitcher.Core" />
            <section name="msie" type="JavaScriptEngineSwitcher.Msie.Configuration.MsieConfiguration, JavaScriptEngineSwitcher.Msie" />
            <section name="v8" type="JavaScriptEngineSwitcher.V8.Configuration.V8Configuration, JavaScriptEngineSwitcher.V8" />
        </sectionGroup>

        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor" requirePermission="false" />
        </sectionGroup>

    </configSections>

    <system.web>
        <compilation targetFramework="4.5" debug="true">
            <buildProviders>
                <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" />
            </buildProviders>
        </compilation>
        <httpRuntime targetFramework="4.5" />
        <httpHandlers>
            <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
        </httpHandlers>
        <pages controlRenderingCompatibilityVersion="4.0" />
    </system.web>

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <validation validateIntegratedModeConfiguration="false" />
        <urlCompression doStaticCompression="true" doDynamicCompression="false" />
        <handlers>
            <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
        </handlers>

        <security>
            <requestFiltering>
                <hiddenSegments>
                    <add segment="ClearScript.V8" />
                </hiddenSegments>
            </requestFiltering>
        </security>
    </system.webServer>

    <jsEngineSwitcher xmlns="http://tempuri.org/JavaScriptEngineSwitcher.Configuration.xsd">
        <core>
            <engines>
                <add name="MsieJsEngine" type="JavaScriptEngineSwitcher.Msie.MsieJsEngine, JavaScriptEngineSwitcher.Msie" />
                <add name="V8JsEngine" type="JavaScriptEngineSwitcher.V8.V8JsEngine, JavaScriptEngineSwitcher.V8" />
            </engines>
        </core>
    </jsEngineSwitcher>

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>

            <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

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

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc" />
        <pages pageBaseType="ServiceStack.Razor.ViewPage">
            <namespaces>
                <add namespace="System" />
                <add namespace="ServiceStack" />
                <add namespace="ServiceStack.Html" />
                <add namespace="ServiceStack.Razor" />
                <add namespace="ServiceStack.Text" />
                <add namespace="ServiceStack.OrmLite" />
                <add namespace="ConnectDevelop.Configuration.Web" />
            </namespaces>
        </pages>
    </system.web.webPages.razor>
</configuration>

我还添加?debug=requestinfo到请求的末尾,但在输出中看不到任何明显的错误。

任何帮助,将不胜感激。

4

1 回答 1

1

查看Views 与 Content Pages之间的区别,即该/Views文件夹是视图页面的特殊文件夹,仅使用服务的结果执行(即类似于 ASP.NET MVC 控制器 + 视图)。

本质上 Razor 页面/Views不能直接调用,而外部的 razor 页面/Views只能直接调用。

于 2015-06-11T13:55:10.563 回答