2012-02-17 61 views
0

我剛剛創建了一個新的MVC3項目,並通過nuget安裝了servicestack mvc。然後我在Global.asax.cs中添加這的RegisterRoutes,按的README.txt:使用MVC3的servicestack,不工作

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

Servicestack給出了這樣的錯誤:

The resource cannot be found. 

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

除非我註釋掉這Global.asax.cs中:

 routes.MapRoute(
      "Default", // Route name 
      "{controller}/{action}/{id}", // URL with parameters 
      new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
     ); 

我怎樣才能讓MVC3和Servicestack工作。我正在使用VS2010,IIS7。

+0

你安裝ServiceStack.Host.Mvc?並且你的Web.config肯定是在/ api路由上裝了ServiceStack? (這應該由NuGet安裝完成)。什麼網址給你404? – mythz 2012-02-17 16:59:38

+0

@mythz道歉,我沒有意識到你發表了評論。是的,我認爲Web.config是正確的。 localhost:28945/api給出了404,當我之前提到的這一行沒有被註釋掉。我已經上傳了一個示例項目來說明這個問題:dl.dropbox.com/u/49815808/StackOverflow/Test2.zip – Michael 2012-03-01 11:52:09

+1

@Michael - 並不完全確定,但看着上面的IgnoreRoute,您可能需要使用前面的斜槓路線被忽略。試試http:// localhost:28945/api /。 – 2012-03-19 09:44:25

回答

0

嘗試做這兩個步驟:

中的Application_Start 1.停用MVC的WebAPI註冊。

//WebApiConfig.Register(GlobalConfiguration.Configuration); 

像 'API /' 2.Ignore MVC路線

routes.IgnoreRoute("api/{*pathInfo}"); 
+0

並遵循[MVC Integration wiki!](https://github.com/ServiceStack/ServiceStack/wiki/Mvc-integration):) – mythz 2013-11-06 14:07:02