c# - 如何将服务堆栈 4 与 asp.net MVC 4 并行安装?

标签 c# asp.net-mvc-4 routes localhost servicestack

我已经完成了 servicestack 文档中的所有步骤,并遵循了 Stack Overflow 上类似帖子的建议,但是每当我尝试访问我的“/api/”路由时,我都会收到以下错误:

Handler for Request not found: 


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

相关代码段:

应用程序主机:

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

路由配置.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 }
            );
        }

此外,当我在浏览器的地址栏中键入“localhost:port/api”时,浏览器被重定向到“localhost:port/api/api/metadata”,这是我收到错误消息的地方。它不允许我访问“localhost:port/api/metadata”。

最佳答案

终于有人帮助完全消除了元数据。 您需要输入:

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

关于c# - 如何将服务堆栈 4 与 asp.net MVC 4 并行安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20572755/

相关文章:

c# - 该文件正在被另一个进程使用,我必须关闭它吗?如何?

asp.net-mvc - 发布到服务器时 MVC ActionLinks 呈现为空

javascript - MVC 4 和 JavaScript

routes - Preact 路由器 : Modify URL

javascript - Ajax - GET 方法不发送参数

c# - 在 digi 6030dx 调制解调器上使用 SSH.NET 执行命令 - 以左方括号开头的字符序列是什么?

c# - 如何为构造函数自定义 Visual Studio 的私有(private)字段生成快捷方式?

c# - 更新现有的 Outlook 约会

javascript - 没有 Razor 编码的 MvcHtmlString

php - Laravel Route 模型绑定(bind)(slug)仅适用于 show 方法?