asp.net-mvc-4 - 与 MVC 并排运行 ServiceStack

标签 asp.net-mvc-4 servicestack

我设法将 ServiceStack 与 MVC4 并排运行,但我仍然有一个小问题,希望有人能帮助我解决这个问题。

当通过 VS2012 执行调试 session 时,一切正常 - 浏览器打开并且第一页加载良好。但是当刷新页面并尝试访问 http://localhost:62322/Content/site.css 时,会显示以下错误:

Handler for Request not found: 

Request.ApplicationPath: /
Request.CurrentExecutionFilePath: /Content/site.css
Request.FilePath: /Content/site.css
Request.HttpMethod: GET
Request.MapPath('~'): D:\All\Projects\ExampleProject\trunk\ExampleProject\ExampleProject\
Request.Path: /Content/site.css
Request.PathInfo: 
Request.ResolvedPathInfo: /Content/site.css
Request.PhysicalPath: D:\All\Projects\ExampleProject\trunk\ExampleProject\ExampleProject\Content\site.css
Request.PhysicalApplicationPath: D:\All\Projects\ExampleProject\trunk\ExampleProject\ExampleProject\
Request.QueryString: 
Request.RawUrl: /Content/site.css
Request.Url.AbsoluteUri: http://localhost:62322/Content/site.css
Request.Url.AbsolutePath: /Content/site.css
Request.Url.Fragment: 
Request.Url.Host: localhost
Request.Url.LocalPath: /Content/site.css
Request.Url.Port: 62322
Request.Url.Query: 
Request.Url.Scheme: http
Request.Url.Segments: System.String[]
App.IsIntegratedPipeline: False
App.WebHostPhysicalPath: D:\All\Projects\ExampleProject\trunk\ExampleProject\ExampleProject
App.DefaultHandler: DefaultHttpHandler
App.DebugLastHandlerArgs: GET|/Content/site.css|D:\All\Projects\ExampleProject\trunk\ExampleProject\ExampleProject\Content\site.css


但是,如果我删除 AppHost.cs 中的以下代码行,一切正常,并且总能找到 site.css 的处理程序:

SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api", DefaultContentType = ContentType.Json });

我对项目的要求是用 ServiceStack 包装通过浏览器(所有 Controller )的任何调用以及对/api 的调用,这应该由 ServiceStack 服务处理。 我按照这里的说明操作: https://github.com/ServiceStack/ServiceStack/wiki/Run-servicestack-side-by-side-with-another-web-framework 我的 web.config 看起来像这样:

<system.web>
    <!--...-->
        <httpHandlers>
          <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
        </httpHandlers>
    <!--...-->
</system.web>
<location path="api">
    <system.web>
      <httpHandlers>
        <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
      </httpHandlers>
    </system.web>
    <!-- Required for IIS 7.0 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
      </handlers>
    </system.webServer>
</location>

有谁知道为什么 site.css 的处理程序有时找到有时找不到? 此外,如果我在配置 ServiceStack 来包装我的整个服务器时犯了错误,请指出它们。

最佳答案

根据您的尝试,我建议您从普通的 ASP.NET Web 应用程序开始。设置项目后,您可以使用 NuGet

Install-Package ServiceStack.Host.AspNet 

或者直接按照配置here .这样做会在根路径/运行 ServiceStack。

在你上面的设置中你不需要这一行...

SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api", DefaultContentType = ContentType.Json });

添加它是告诉 ServiceStack 只处理包含 '/api' 路径的请求,这不是您想要的。

关于asp.net-mvc-4 - 与 MVC 并排运行 ServiceStack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16110598/

相关文章:

c# - 你如何调试 MVC 4 API 路由?

jquery - <head> 中的 RenderSection 缺少文本

c# - MVC Controller 返回一个错误的请求?

c# - 如何在自托管 (AppSelfHostBase) Servicestack 服务 (RequestStream) 上设置文件大小限制?

c# - 为用户订阅 ServiceStack 中的 SSE channel

c# - MVC 4 中的自动工具提示验证?

asp.net - 将 mvc 4 降级/转换为 mvc 3

dependency-injection - 带有 funq 的 servicestack - 按照惯例 Autowiring

c# - 在 ServiceStack 中使用带编号的键反序列化 Json