3

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.

Edi
  • 969
  • 3
  • 9
  • 20
  • I'm a little confused...Do you want ServiceStack to handle all the requests or just requests to '/api'? – paaschpa Apr 19 '13 at 20:11
  • 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 Apr 19 '13 at 21:49
  • 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 Apr 22 '13 at 14:30
  • 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 Apr 22 '13 at 20:08

1 Answers1

1

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.

paaschpa
  • 4,816
  • 11
  • 15
  • Installing this package doesn't really make all the configurations for me. Maybe we didn't understand each other - Is it possible that ServiceStack will handle the controllers/views instead of MVC framework? I need it for the session feature. Thanks. – Edi Apr 23 '13 at 17:29
  • https://github.com/ServiceStack/ServiceStack/wiki/Sessions#sharing-servicestacks-typed-sessions-in-mvc-and-aspnet - Does that help? Not sure what you mean by 'handle the controllers/views'. A ServiceStack Service handles the request and provides the response. It doesn't do anything within MVC controllers/views. – paaschpa Apr 23 '13 at 19:36
  • Thanks, actually there was a misunderstanding. I thought that ServiceStack should handle also the regular MVC controllers in order to main the session and authentication features. Now I removed it from handling the root "/" path and it works perfectly - also the authentication and session still work. – Edi Apr 26 '13 at 14:25