2013-06-26 42 views
1

通过nuget安装ServiceStack: 在新的MVC4应用上安装ServiceStack.Host.Mvc。http:// localhost:1000/api/todos 404使用ServiceStack找不到

阅读“ReadMe.txt”它说: 在Global.asax文件中注释掉WebApiConfig.Register(GlobalConfiguration.Configuration),所以它不会干扰ServiceStack。

而且这是为了增加它,它的工作:

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

这里是我的Global.asax:

public class MvcApplication : System.Web.HttpApplication 
    { 
     protected void Application_Start() 
     { 
      AreaRegistration.RegisterAllAreas(); 

      // WebApiConfig.Register(GlobalConfiguration.Configuration); 
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
      RouteConfig.RegisterRoutes(RouteTable.Routes); 

      BundleConfig.RegisterBundles(BundleTable.Bundles); 
      AuthConfig.RegisterAuth(); 

      RouteTable.Routes.IgnoreRoute("api/{*pathInfo}"); 
      RouteTable.Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); 

      BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles); 
      BootstrapMvcSample.ExampleLayoutsRouteConfig.RegisterRoutes(RouteTable.Routes); 
     } 

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

这是怎样的NuGet配置的web.config中:

<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> 

运行该项目,它会自动启动default.htm页面,该页面具有绑定到/ api/URI的BackBone UI,该页面返回404,我错过了什么?

+0

前前RouteConfig.RegisterRoutes(RouteTable.Routes);

以添加行

RouteTable.Routes.IgnoreRoute("api/{*pathInfo}"); RouteTable.Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); 

或添加行到RouteConfig.cs文件已取出自带的东西的WebAPI与mvc4项目? –

回答

0

路线的登记顺序很重要。我认为你需要的routes.MapRoute()线

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     routes.IgnoreRoute("api/{*pathInfo}"); 
     routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); 

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

谢谢你做到了! – Val

相关问题