并排运行ServiceStack侧MVC [英] Running ServiceStack side by side with MVC
问题描述
我设法用MVC4一边跑一边ServiceStack,但我仍然有一个小问题,希望有人能帮助我这一点。
I managed to run ServiceStack side by side with MVC4, but I still have a little problem and hope someone can help me with that.
在执行通过VS2012调试会话,everthying完美的作品 - 浏览器打开,第一个页面加载好。但随后刷新页面时,并试图让的http://本地主机:62322 /内容/的site.css
,会显示以下错误:
When executing a debugging session through VS2012, everthying works perfect - the browser is opened and the first page is loaded well. But then when refreshing the page, and trying to get to http://localhost:62322/Content/site.css
, the following error is displayed:
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 code的下面一行,一切运作良好,并为的site.css处理程序总是发现:
But if I delete the following line of code in AppHost.cs, everything works well, and the handler for site.css is always found:
SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api", DefaultContentType = ContentType.Json });
我对项目的要求与ServiceStack通过浏览器(所有控制器)的任何调用,以及调用/ API,它应该由ServiceStack服务来处理包装。
我跟着指示在这里:
<一href=\"https://github.com/ServiceStack/ServiceStack/wiki/Run-servicestack-side-by-side-with-another-web-framework\" rel=\"nofollow\">https://github.com/ServiceStack/ServiceStack/wiki/Run-servicestack-side-by-side-with-another-web-framework
和我的web.config看起来像这样:
My requirements for the project are wrapping with ServiceStack any call through the browser (all controllers) as well as calls to /api, which should be handled by a ServiceStack service. I followed the instructions here: https://github.com/ServiceStack/ServiceStack/wiki/Run-servicestack-side-by-side-with-another-web-framework and my web.config looks like this:
<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我的包裹整个服务器,请点我给他们。
Does anybody know why the handler for site.css sometimes found and sometimes not? Furthermore, if I did a mistake with configuring ServiceStack to wrap my whole server, please point me to them.
推荐答案
从你正在尝试做的,我会建议先从一个简单的ASP.NET Web应用程序。一旦你的项目设置,使用的NuGet你可以做
From what you are trying to do I would recommend starting with a plain ASP.NET Web Application. Once your project is set, using NuGet you could do
Install-Package ServiceStack.Host.AspNet
或只需按照配置这里。这样做运行ServiceStack的根路径/.
or just follow the configuration here. Doing this runs ServiceStack at the root path /.
在您的设立上面,你不需要这行...
In your set up above you don't need this line...
SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api", DefaultContentType = ContentType.Json });
添加它告诉ServiceStack只处理包含是不是你想要的是什么/ API
路径请求。
Adding it is telling ServiceStack to only handle requests that contain the '/api'
path which is not what you want.
这篇关于并排运行ServiceStack侧MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!