-
Notifications
You must be signed in to change notification settings - Fork 0
Run servicestack side by side with another web framework
In order to avoid conflicts with your existing ASP.NET web framework it is recommended to host your ServiceStack web services at a custom path. This will allow you to use ServiceStack together with an existing web framework e.g. ASP.NET MVC 3 or FUBU MVC, etc.
The location configuration (to your root Web.config file) below hosts your webservices at custom path: /api
<configuration>
. . .
<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>
. . .
</configuration>
<!-- Required for MONO -->
<configuration>
. . .
<system.web>
<httpHandlers>
<add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
. . .
</configuration>
Note: Due to limitations in IIS 6 - the
/custompath
must end with.ashx
, e.g:path="servicestack.ashx"
You also need to configure the root path in your AppHost.
public override void Configure(Container container)
{
SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" });
}
To avoid conflicts with ASP.NET MVC add an ignore rule in Global.asax RegisterRoutes
method e.g: routes.IgnoreRoute ("api/{*pathInfo}");
For MVC4 applications you also need to unregister WebApi, by commenting out this line in Global.asax.cs
:
//WebApiConfig.Register(GlobalConfiguration.Configuration);
Due to Mono bug you need to set up explicitly ASP.NET auth to 'windows' mode when using ServiceStack auth on Mono, otherwise auth will be always redirected to /login.aspx insted of getting nice 401 (invalid username or password) response.
Add to web.config
under system.web
section.
<!-- Required to use ServiceStack auth under Mono -->
<authentication mode="Windows" />
See also:
- Why ServiceStack?
- What is a message based web service?
- Advantages of message based web services
- Why remote services should use separate DTOs
- Getting Started
- Reference
- Clients
- Formats
- View Engines 4. Razor & Markdown Razor
- Hosts
- Advanced
- Configuration options
- Access HTTP specific features in services
- Logging
- Serialization/deserialization
- Request/response filters
- Filter attributes
- Concurrency Model
- Built-in caching options
- Built-in profiling
- Messaging and Redis
- Form Hijacking Prevention
- Auto-Mapping
- HTTP Utils
- Virtual File System
- Config API
- Physical Project Structure
- Modularizing Services
- Plugins
- Tests
- Other Languages
- Use Cases
- Performance
- How To
- Future