【发布时间】:2014-04-22 11:47:21
【问题描述】:
我正在尝试在没有 MVC 的情况下使用 Razor。我创建了一个新的 ASP.NET 空 Web 应用程序,然后安装了以下包:Microsoft.AspNet.Razor
然后我在我的目录的根目录中有一个Index.cshtml,但是当我启动该站点时,我收到以下错误:
HTTP Error 403.14 - Forbidden
A default document is not configured for the requested URL,
and directory browsing is not enabled on the server.
如果我添加一个 Index.html 文件,它可以正常工作,但我想使用 Razor。我需要做任何额外的配置吗?我的web.config 看起来像这样:
<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>
我正在使用 Visual Studio 2013 和 IIS Express 8
注意
我所做的只是创建一个新的空 Web 应用程序,未选中 Web API、Web 表单、MVC,没有身份验证。
已安装:Microsoft.AspNet.Razor 通过 nuget。
在根目录下创建Index.cshtml 页面并在本地启动站点以重现错误。
【问题讨论】:
-
陈述你的目的?是为了完整的网页生成还是使用模板之类的东西来生成文档(比如html文档)?
-
好吧,如果你想从马口中听到它:stackoverflow.com/a/5266583/145682
-
并不是因为他们在谈论在 .aspx 页面中使用 Razor 语法 (@),而我只是希望 IIS 呈现呈现为 html 的 .cshtml 页面?
-
@TrueBlueAussie
Razorsyntax 并不“需要”控制器——正如 BillBaffBoff 所说... -
我明白你的意思,但添加整个 MVC 框架只是为了让剃须刀工作似乎有点冗长..