2

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:

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

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();
    }
}

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>

And of course the default.cshtml:

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

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

jklemmack
  • 3,518
  • 3
  • 30
  • 56
  • 2
    Do you have any StartUp Errors on your [?debug=requestinfo](https://github.com/ServiceStack/ServiceStack/wiki/Debugging#request-info) page? – mythz Mar 27 '14 at 22:58
  • Wow - how did I miss that option!? I'm getting: "Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=e06fbc6124f57c43' or one of its dependencies." I'm running VS2012 and just used NuGet to install ServiceStack.Razor. – jklemmack Mar 27 '14 at 23:22
  • 1
    ok in that case it'll be this [ASP.NET WebPages dependency issue](http://stackoverflow.com/a/22671119/85785). – mythz Mar 27 '14 at 23:28
  • Okay, I've tried two things. 1) "Install-Package Microsoft.AspNet.WebPages", bringing in version 3.1.1. Afterwards, the compilation section of web.config says "assembly="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35". This errors - note the thumbprints don't match. 2) I explicitly install AspNet web pages version 3.0.0 and same issue. – jklemmack Mar 28 '14 at 00:13
  • Does what's on the Web.config not match the dll? If it doesn't work when they're both in-sync, just import v1: `Install-Package Microsoft.AspNet.WebPages -Version 1.0.20105.408` – mythz Mar 28 '14 at 00:18
  • @mythz I think I just had a bad cached item somewhere. I stopped IIS Express; un- and re-installed Microsoft.AspNet.WebPages v3.1.1, ServiceStack.Razor; then wiped the temp files in c:\windows\Microsoft.Net\... everything worked file after a rebuild. – jklemmack Mar 28 '14 at 06:11
  • ok cool glad it's sorted. Can you add that down as the answer, thx. – mythz Mar 28 '14 at 06:41

1 Answers1

5

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

  • 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.
jklemmack
  • 3,518
  • 3
  • 30
  • 56
  • Having run into this again on a new project a month later, it seems the order in which the NuGet packages are installed might matter. `Microsoft.AspNet.WebPages` first, then `ServicesStack.Razor` – jklemmack Apr 29 '14 at 15:26