【问题标题】:ServiceStack Razor cshtml pages not served on development machineServiceStack Razor cshtml 页面未在开发机器上提供
【发布时间】:2013-01-03 19:22:32
【问题描述】:

我在处理 ServiceStack Razor 项目时看到不一致的结果。问题是某些项目开始无法在我的开发环境(Win 8,VS 2012)中提供 cshtml 页面。使用 IIS Express 调试主页(default.cshtml)返回:

Forbidden

Request.HttpMethod: GET
Request.PathInfo:
Request.QueryString: 
Request.RawUrl: /default.cshtml
App.IsIntegratedPipeline: True
App.WebHostPhysicalPath: C:\Users\jim\Documents\Visual Studio > 2012\Projects\Test.Web\Test.Web
App.WebHostRootFileNames: [about.cshtml,apphost.cs,default.cshtml,global.asax,global.asax.cs,packages.config,pricing.cshtml,privacy.cshtml,reconcilable.web.csproj,test.web.csproj.user,terms.cshtml,web.config,web.debug.config,web.release.config,bin,obj,properties,public,services,views]
App.DefaultRootFileName: default.cshtml

如果我在不同的 URL 上请求页面,我会看到以下内容:

Handler for Request not found: 

Request.ApplicationPath: /
Request.CurrentExecutionFilePath: /terms
Request.FilePath: /terms
Request.HttpMethod: GET
Request.MapPath('~'): C:\Users\jim\Documents\Visual Studio 2012\Projects\Test.Web\Test.Web\
Request.Path: /terms
Request.PathInfo: 
Request.ResolvedPathInfo: /terms
Request.PhysicalPath: C:\Users\jim\Documents\Visual Studio 2012\Projects\Test.Web\Test.Web\terms
Request.PhysicalApplicationPath: C:\Users\jim\Documents\Visual Studio 2012\Projects\Test.Web\Test.Web\
Request.QueryString: 
Request.RawUrl: /terms
Request.Url.AbsoluteUri: http://localhost:51000/terms
Request.Url.AbsolutePath: /terms
Request.Url.Fragment: 
Request.Url.Host: localhost
Request.Url.LocalPath: /terms
Request.Url.Port: 51000
Request.Url.Query: 
Request.Url.Scheme: http
Request.Url.Segments: System.String[]
App.IsIntegratedPipeline: True
App.WebHostPhysicalPath: C:\Users\jim\Documents\Visual Studio 2012\Projects\Test.Web\Reconcilable.Web
App.WebHostRootFileNames: [about.cshtml,apphost.cs,default.cshtml,global.asax,global.asax.cs,packages.config,test.web.csproj,test.web.csproj.user,terms.cshtml,web.config,web.debug.config,web.release.config,bin,obj,properties,public,services,views]
App.DefaultRootFileName: default.cshtml
App.DefaultHandler: default.cshtml
App.DebugLastHandlerArgs: GET|/terms|C:\Users\jim\Documents\Visual Studio 2012\Projects\Test.Web\Test.Web\terms

我可以创建一个干净的新项目以正确地提供页面,但是具有相同 web.config、AppHost、Global.asax 文件的旧项目会失败。代码如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.web>
    <compilation 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>
  </system.web>
  <!-- Required for IIS 7.0 -->
  <system.webServer>
    <handlers>
      <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
  </system.webServer>
  <appSettings>
    <add key="webPages:Enabled" value="false" />
  </appSettings>
  <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.Html" />
        <add namespace="ServiceStack.Razor" />
        <add namespace="ServiceStack.Text" />
        <add namespace="ServiceStack.OrmLite" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

public class Global : HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        new AppHost().Init();
    }

}

public class AppHost : AppHostBase
{
    public AppHost() : base("test", typeof(AppHost).Assembly) { }

    public override void Configure(Funq.Container container)
    {
        Plugins.Add(new RazorFormat());
    }
}

当项目部署到服务器时,我没有看到同样的问题。有人能给我一些可能导致这种情况的想法吗?

【问题讨论】:

    标签: servicestack iis-express


    【解决方案1】:

    回答我自己的问题:

    我认为这个问题是我的开发机器特有的。当我在家用 PC 上调试站点时,没有问题。我的结论是我的开发机器的配置导致了这个问题。我想我需要查看机器而不是代码来尝试解决这个问题。

    【讨论】:

    • 我遇到了同样的问题;你发现问题是什么了吗?
    • 我也是,有什么解决办法吗?
    • 有一种解决方法。更改您的 cshtml 文件属性以复制是否较新并检查它是否正常工作。这是错误的,但可能会有所帮助。
    • 完全一样!快把我逼疯了 !新项目没问题,当前项目:没有 .cshtml 以任何方式提供服务:/.. 删除了所有内容,更改了整个 web.config...IIS 真的是一个不起眼的野兽...
    猜你喜欢
    • 2012-10-23
    • 1970-01-01
    • 2021-09-12
    • 2022-09-24
    • 2021-11-10
    • 1970-01-01
    • 2012-01-02
    • 2012-01-13
    • 2020-05-16
    相关资源
    最近更新 更多