3
votes

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.

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


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 });

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>

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.

1
I'm a little confused...Do you want ServiceStack to handle all the requests or just requests to '/api'?paaschpa
I want it to handle all the requests - controllers and also /api. But regarding static content such as "/content/site.css", i don't care if it's handled by ServiceStack or by MVC)Edi
If you want ServiceStack to handle all your incoming requests, why do you need MVC4? ServiceStack 'takes over' the request/response pipeline. In the setup you are after MVC4 Controllers would not receive/handle any incoming requests. Hosting at a custom path (like /api) lets ServiceStack handle requests to a specific path and MVC4 handle everything else.paaschpa
That's right, I don't want MVC to handle my requests. I guess that the subject was confusing. Currently ServiceStack handles all of the requests, that's ok - but sometimes I get the "Handler for Request not found" error. And this is the problem.Edi

1 Answers

1
votes

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 

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 });

Adding it is telling ServiceStack to only handle requests that contain the '/api' path which is not what you want.