1

I'm trying to use Razor without MVC.. I've created a new ASP.NET Empty Web Application and then installed the following package: Microsoft.AspNet.Razor

I've then got an Index.cshtml in the root of my directory but when I launch the site I get the following error:

HTTP Error 403.14 - Forbidden
A default document is not configured for the requested URL, 
    and directory browsing is not enabled on the server.

If I add an Index.html file it works fine, but I'd like to use Razor. Is there any additional configuration I need to do? My web.config looks like this:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>

  </runtime>
</configuration>

I'm using Visual Studio 2013 and IIS Express 8

Note

All I've done is create a new empty web application, left Web API, Web Forms, MVC unchecked, no authentication.

Installed: Microsoft.AspNet.Razor through nuget.

Created Index.cshtml page in the root and launched the site locally to reproduce the error.

CallumVass
  • 11,288
  • 26
  • 84
  • 154
  • State your purpose? Is it for a complete web page generation or to use something like a template to generate documents (like html documents)? – deostroll Mar 17 '14 at 10:40
  • To generate complete web pages.. More specifically I want to make use of the bundling in `Microsoft.AspNet.Web.Optimization` – CallumVass Mar 17 '14 at 10:42
  • 1
    Well, if you want to hear it from the horses mouth: http://stackoverflow.com/a/5266583/145682 – deostroll Mar 17 '14 at 10:47
  • But the answers there will definitely help you I guess... – deostroll Mar 17 '14 at 10:48
  • 1
    Not really because they're talking about using Razor syntax (@) inside an .aspx page, where as I just want IIS to render a .cshtml page rendered as html? – CallumVass Mar 17 '14 at 10:51
  • That feature is called *[Asp.net Web Pages](http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2)*, and you need WebMatrix installed for it. – deostroll Mar 17 '14 at 10:56
  • 1
    @TrueBlueAussie `Razor` _syntax_ doesn't "require" controllers - exactly as BillBaffBoff stated... – EdSF Mar 17 '14 at 13:31
  • I don't know why anyone feels adding a single controller is not a good idea in this instance (why fight city hall), but I have removed my answer. Good luck. – iCollect.it Ltd Mar 17 '14 at 15:58
  • 1
    I see your point but adding in the whole MVC framework just to get razor working seems a bit verbose.. – CallumVass Mar 17 '14 at 16:12

2 Answers2

0

HTTP Error 403.14 - Forbidden A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

The above is more indicative of an IIS/ASP.Net matter than "Razor" sytnax. Does the site you configured have ASP.Net (enabled?), AppPool (.net 4), etc? The reason index.html works is that it's just-an-html-page that IIS will happily serve vs. a csthtml (or aspx, vbhtml) which are application specific (ASP.Net).

EdSF
  • 11,753
  • 6
  • 42
  • 83
  • I'm not using Razor in WebForms or MVC, at the moment its just an empty ASP site with 1 file (Index.cshtml) when I run it in IIS Express using Visual Studio 13 I get that error – CallumVass Mar 17 '14 at 14:53
  • @BiffBaffBoff - you mean "use IIS Express" in VS or some other way (e.g. like manually creating an IIS site)? What happens if you explicitly browse `index.chtml`? – EdSF Mar 17 '14 at 17:33
  • Yeah, IIS Express in VS. When I browse `/Index.cshtml` it says the server isn't allowed to display that file type. I've got colleagues to try this on their machine and they all get the same error. – CallumVass Mar 17 '14 at 17:40
  • @BiffBaffBoff That's a sign that your "site" isn't setup to handle cshtml files (IIS/ASP.net settings and/or needed assemblies). Does your `/bin` folder have the [necessary dlls to handle](http://stackoverflow.com/a/5908903/304683)? – EdSF Mar 17 '14 at 18:59
0

See my answer here. Your problem can be related to the mapping of your resorces.

Community
  • 1
  • 1
bogdan.rusu
  • 901
  • 4
  • 21
  • 41