我已经完成了 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/