Service Stack on MVC4

前端 未结 3 807

I am just trying to get Service Stack running under a mvc4 project. Does the ServiceStack.Host.Mvc nuget package work with mvc 4.0 ? I installed it and added

3条回答
  •  感情败类
    2021-01-01 20:11

    In the README.txt page when you install the ServiceStack.Host.Mvc NuGet package shows the instructions needed for installing ServiceStack with MVC, we've added an extra line for support with MVC4 since it comes bundled with a conflicting WepApi.

    For MVC4 applications you also need to unregister WebApi, by commenting out this line:
    
        //WebApiConfig.Register(GlobalConfiguration.Configuration);
    

    We also dislike having to provide manual install instructions to disable WebApi from the default install of MVC4 but unfortunately this is the best we can do at the moment with what's available.

    The ServiceStack docs is a community wiki

    If you feel there is something missing from ServiceStack's wiki docs, please feel free to add them, as they are a community wiki docs maintained by and are for the ServiceStack community.

    Asking the aspnetwebstack team for an easier way to disable WebApi

    We've already requested from the aspnetwebstack team if they could provide an easier and automated way to be able to disable WebApi via Nuget, feel free to show your support of this feature by commenting on the feature request.

    Full README.txt instructions

    To make the README more searchable I will repeat them here:


    Hosting in ASP.NET MVC is very similar to hosting in any ASP.NET framework, i.e. The ServiceStack AppHost still needs to be initialized on start up in your Global.asax.cs (or WebActivator), e.g:

    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            new AppHost().Init();
        }
    }
    

    You MUST register ServiceStacks '/api' path by adding the lines below to MvcApplication.RegisterRoutes(RouteCollection) in the Global.asax:

    routes.IgnoreRoute("api/{*pathInfo}"); 
    routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); //Prevent exceptions for favicon
    

    Place them before the current entries the method.

    For MVC4 applications you also need to unregister WebApi, by commenting out this line:

        //WebApiConfig.Register(GlobalConfiguration.Configuration);
    

    To enable the Mini Profiler add the following lines in to MvcApplication in Global.asax.cs:

    protected void Application_BeginRequest(object src, EventArgs e)
    {
        if (Request.IsLocal)
            ServiceStack.MiniProfiler.Profiler.Start();
    }
    
    protected void Application_EndRequest(object src, EventArgs e)
    {
        ServiceStack.MiniProfiler.Profiler.Stop();
    }
    

    For more info on the MiniProfiler see v3.09 of the https://github.com/ServiceStack/ServiceStack/wiki/Release-Notes

    The Urls for metadata page and included Services:

    • /api/metadata - Auto generated metadata pages
    • /api/hello - Simple Hello World Service see: http://www.servicestack.net/ServiceStack.Hello/
    • /api/todos - Simple REST Service see: http://www.servicestack.net/Backbone.Todos/
    • /default.htm - Backbone.js TODO application talking to the TODO REST service at /api/todos

提交回复
热议问题