ServiceStack View 403 (Forbidden)

572 views Asked by At

I have setup Service Stack web project with a couple of views. I can access the /Default.cshtml view without any problems but when I try to access anything in the /Views/ folder I get the below error:

Forbidden

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

I have looked at the answers here and here as well as many others but I can't seem to figure this out.

Here is my view:

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

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

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

I've also added ?debug=requestinfo to the end of the request but I can't see any obvious errors in the output.

Any help would be appreciated.

1

There are 1 answers

0
mythz On BEST ANSWER

See the difference between Views vs Content Pages, i.e. the /Views folder is a special folder for view pages that are only executed with the result of a Service (i.e. similar to ASP.NET MVC Controllers + Views).

Essentially Razor pages in /Views can't be called directly, where as razor pages outside of /Views can only be called directly.