简体   繁体   English

如何与asp.net MVC 4并排安装服务堆栈4?

[英]How do I install service stack 4 side-by-side with asp.net MVC 4?

I've gone through all of the steps in the servicestack documentation and followed the advice of a similar post here on Stack Overflow, but whenever I try to access my "/api/" route, I get the following error: 我已经完成了servicestack文档中的所有步骤,并遵循了Stack Overflow上类似文章的建议,但是每当我尝试访问“ / api /”路由时,都会出现以下错误:

Handler for Request not found: 


Request.HttpMethod: GET
Request.PathInfo: /api/metadata
Request.QueryString: 
Request.RawUrl: /api/api/metadata

Relevant sections of code: 代码的相关部分:

AppHost: AppHost:

public class HolidayEventPlannerAppHost : AppHostBase
    {
        public HolidayEventPlannerAppHost() : base("Holiday Event Planner App Host", typeof(HelloService).Assembly) { }

        public override void Configure(Funq.Container container)
        {
            SetConfig(new HostConfig { HandlerFactoryPath = "api" });
        }
    }

Routeconfig.cs: Routeconfig.cs:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("api/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

In addition, when I type "localhost:port/api" in my browser's address bar, the browser gets redirected to "localhost:port/api/api/metadata" which is where I get the error message. 另外,当我在浏览器的地址栏中键入“ localhost:port / api”时,浏览器将重定向到“ localhost:port / api / api / metadata”,这是我收到错误消息的地方。 It won't let me access "localhost:port/api/metadata". 它不会让我访问“ localhost:port / api / metadata”。

Finally someone that help to eliminate the metadata completely. 最后有人帮助彻底消除元数据。 You need to put: 您需要输入:

SetConfig(new HostConfig
    {
        HandlerFactoryPath = "api",
        MetadataRedirectPath = "/"
    }); 

I am using ServiceStack 3.9.70, for me in order to use ServiceStack along with MVC WebApi I had to do this: 我正在使用ServiceStack 3.9.70,对我来说,为了与MVC WebApi一起使用ServiceStack,我必须这样做:

SetConfig(new EndpointHostConfig
    {
        ServiceStackHandlerFactoryPath = "sapi",
        MetadataRedirectPath = "sapi/metadata"
     });

This way I can use api for WebAPI and sapi for ServiceStack. 这样,我可以将api用于WebAPI,将sapi用于ServiceStack。 Don't forget you need to modify the Web.Config also, full instruction here . 别忘了您还需要修改Web.Config, 这里有完整的说明

There's an existing template for hosting ServiceStack with MVC4 , you'd also want to ensure that your Web.config is properly configured for ServiceStack, which you can compare with the Mvc4 Web.Config . 有一个用于托管带有MVC4的ServiceStack的现有模板,您还想确保已为ServiceStack正确配置了Web.config,可以将其与Mvc4 Web.Config进行比较。

More information about integration with MVC is available on the wiki . 有关与MVC集成的更多信息, 请参见Wiki

I've had similar issues with this redirect path since using v4 of ServiceStack. 自从使用ServiceStack v4以来,此重定向路径存在类似问题。

As a fix, I found that overriding the MetadataRedirectPath with the following HostConfig worked: 作为修复,我发现使用以下HostConfig覆盖MetadataRedirectPath是HostConfig

        SetConfig(new HostConfig
        {
            HandlerFactoryPath = "api",
            MetadataRedirectPath = "/metadata"
        });

I think without this config, a bug is being exposed in either how the default MetadataRedirectPath is determined or how the redirect url is combined with the handler factory path. 我认为,如果没有此配置,则无论是如何确定默认的MetadataRedirectPath还是将重定向URL与处理程序工厂路径组合在一起都将暴露一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM